忽略路由ASP.NET 4 WebForms的嵌入式资源 [英] Ignore embedded resources routing ASP.NET 4 WebForms

查看:62
本文介绍了忽略路由ASP.NET 4 WebForms的嵌入式资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net 4网络表单中使用路由。我有一个主题dll,其中包含外观所需的所有图像,css和js文件。我只有1个页面,该页面会在页面中动态加载控件。我使用路由来区分请求。定义了以下路由:

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

已经定义了用于管理嵌入式资源的处理程序。当应用程序通过代码执行时,会将请求重定向到default.aspx。

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.

我希望它将css / jpg请求路由到虚拟路径处理程序,而不是将其路由到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(/.*)?" }); 

这解决了我的问题。

这篇关于忽略路由ASP.NET 4 WebForms的嵌入式资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆