문제

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.

도움이 되었습니까?

해결책

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
    );
}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top