开发者

Ignore embedded resources routing ASP.NET 4 WebForms

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 resourc开发者_Python百科es 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜