Use System.Web.Mvc in non MVC ASP.NET Web Forms Application

469 views Asked by At

We are developing an ASP.NET Web Forms application with REST modelled URL, for which we are using Route tables in global.asax. However, recently we came over a problem where the WebResource.axd and ScriptResource.axd files were getting routed as well. We wanted to use the RouteCollection.IgnoreRoute function. However, since it in System.Web.Mvc, it would mean that we would need to reference that dll in a non MVC Web Forms application.

Is it safe for us to continue with the approach. If anyone has a better way to ignore routes from within the Web Forms application please do share. Please also note that the application has been extensively developed in Web Forms and moving to MVC at the current stage is not feasible.

2

There are 2 answers

0
Registered User On BEST ANSWER

For web forms you need to use System.Web.Routing

Put this is Global.asax

void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
    routes.Ignore("{resource}.axd/{*pathInfo}");

    routes.MapPageRoute(
       "Home",      // Route name
       "WWWWWW",      // Route URL
       "~/Default.aspx" // Web page to handle route
    );
}
0
Dmytro Shevchenko On

Did you know you could safely run an ASP.NET Web Forms and MVC application combined? Here are some links:

Also, you can just use URL routing in ASP.NET 4 applications, as Registered User pointed out above. Read more about it here: http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx