Ignore embedded resources routing ASP.NET 4 WebForms

天涯浪子 提交于 2019-12-12 05:29:33

问题


I am using routing in asp.net 4 webforms. I have a theme dll which contains all the images, css and js files required for look and feel. I have only 1 page which dynamically loads the control in the page. I use routing to distinguish the request. Following routes are defined:

routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("Default-All-Pages", "Pages/{*OtherParams}", "~/Default.aspx", false);

Handler for managing the embedded resources is already defined. When the application is executed it by virtue of code, redirects the request to default.aspx. it then goes ahead to load the css file and again routes the request to default.aspx.

I want it to route the css/jpg request to virtual path handler and not the page. What route should I define so that the request for files will not be handled by default.aspx page?


回答1:


routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" }); 
routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" }); 
routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" }); 
routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" }); 

This solved my problem.




回答2:


The same way you're ignoring HttpHandlers, you can add ignore rules for css and jpg files:

routes.Ignore("{resource}.css/{*pathInfo}");
routes.Ignore("{resource}.jpg/{*pathInfo}");

These will be excluded from the route table and will be handled by any registered handlers/modules/ISAPI filters.



来源:https://stackoverflow.com/questions/5674329/ignore-embedded-resources-routing-asp-net-4-webforms

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