Search code examples
c#webformsasp.net-coreasp.net-routingasp.net-core-mvc

Using Routing to return a WebForms page


If I have a simple Default.aspx WebForms page under Views/WebForms/Default.aspx, how do I configure the MVC routing to open the Default.aspx page at startup?

I've tried reading some articles regarding the MVC 6 routing, but I don't think they're mentioning anything about incorporating WebForms routing with the new MVC 6. (I know WebForms is kind of deprecated but still supported in ASP.NET 5)

Articles:

I think I have to use the IApplicationBuilder.UseRouter method, but not sure how to accomplish that.

Here's what I have attempted:

RouteCollection routes = new RouteCollection();
routes.Add(new TemplateRoute(new WebFormsRouterHandler(), "test", null));
app.UseRouter(routes);

And here's the WebFormsRouterHandler:

public class WebFormsRouterHandler : IRouter
{
    public string GetVirtualPath(VirtualPathContext context)
    {
        throw new NotImplementedException();
    }

    public Task RouteAsync(RouteContext context)
    {

    }
}

I'm not sure what to put in RouteAsync method..return the WebForms perhaps?


Solution

  • There is no support in ASP.NET 5 for Web Forms or the ASPX view engine.

    What you can do is redirect to a WebForm application on .NET 4.5/4.6, or better yet port your default.aspx to razor.

    As for the answer above - ASP.NET 5 does not yet support Web Pages. We have prototyped it and plan to have it in one of the releases after V1 RTM.