ASP.NET MVC routing issue?

余生长醉 提交于 2019-12-13 07:34:36

问题


I keep getting errors like this after my pages are done refreshing.

The controller for path '/S43G/S4_Manager/WebResource.axd' could not be found or it does not implement IController.

but I get the error for any file that does not exist on my hard drive. regardless of extension (.png, .css, etc)

I've tried all of the following to fix it, and I'm stumped.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute( "{resource}.axd" );
routes.IgnoreRoute( "WebResource.axd" );

routes.MapRoute(
"Default",                                              // Route name
"{controller}/{action}/{id}",                           // URL with parameters
new { controller = "Home", action = "Index", id = "" },  // Parameter defaults
new { controller = @"[^\.]*" }
            );

Any ideas what I need to put in my routing to prevent it throwing exceptions everytime a file does not exists.

barring those how to I fix the WebResoruce.axd issue, since WebResoruce.axd not supposed to exist.

Thanks,

Eric=


回答1:


I think my answer here gives a solution to your problem, simply match all urls and use a constraint to check if the filetype is .axd.

Then all you need is the following to handle 404 requests after all other MapRoutes():

 routes.MapRoute(
           "Error404CatchAll", // Route name  
           "{*url}", // URL with parameters
           new { controller = "Error", action = "Http404" } // Parameter defaults
           );


来源:https://stackoverflow.com/questions/1609726/asp-net-mvc-routing-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!