如何忽略少数文件类型 asp.net 4.0 的路由
假设我希望路由应该忽略 *.js 文件 *.css 和 *.png 等
我搜索谷歌并找到解决方案。我在我的页面中实现了它,但仍然没有下载 js 文件。
这是我的代码
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Ignore("images/{*pathInfo}");
RouteTable.Routes.Ignore("Scripts/{*pathInfo}");
RouteTable.Routes.Ignore("Styles/{*pathInfo}");
RouteTable.Routes.MapPageRoute("Source", "UrlRewrite/Approach1/Source/{ID}/{Title}", "~/UrlRewrite/Approach1/Source.aspx");
RouteTable.Routes.MapPageRoute("Source2", "UrlRewrite/Approach1/Source/{Question}/{ID}/{Title}/{Page}", "~/UrlRewrite/Approach1/Source.aspx");
RouteTable.Routes.MapPageRoute("Source1", "Feedback/{ID}/{Title}", "~/Feedback.aspx");
//RouteTable.Routes.MapPageRoute("Source1", "Source.aspx{?}{ID}{&}{Title}", "~/UrlRewrite/Approach1/Source.aspx");
RouteTable.Routes.MapPageRoute("product", "Data/product.aspx/{*ID}", "~/UrlRewrite/Approach1/Source.aspx"); // url mapping with * routing
}
,所以告诉我我的代码可以忽略少数文件类型。为什么我的js没有下载。 我的 css 文件位于 Styles 文件夹中,我的 js 文件位于 Script 文件夹等中。根目录中的 Styles 文件夹。请指导我。谢谢
suppose i want that routing should ignore *.js files *.css and *.png etc
i search google and found solution. which i implement in my page but still js files are not downloading.
here is my code
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Ignore("images/{*pathInfo}");
RouteTable.Routes.Ignore("Scripts/{*pathInfo}");
RouteTable.Routes.Ignore("Styles/{*pathInfo}");
RouteTable.Routes.MapPageRoute("Source", "UrlRewrite/Approach1/Source/{ID}/{Title}", "~/UrlRewrite/Approach1/Source.aspx");
RouteTable.Routes.MapPageRoute("Source2", "UrlRewrite/Approach1/Source/{Question}/{ID}/{Title}/{Page}", "~/UrlRewrite/Approach1/Source.aspx");
RouteTable.Routes.MapPageRoute("Source1", "Feedback/{ID}/{Title}", "~/Feedback.aspx");
//RouteTable.Routes.MapPageRoute("Source1", "Source.aspx{?}{ID}{&}{Title}", "~/UrlRewrite/Approach1/Source.aspx");
RouteTable.Routes.MapPageRoute("product", "Data/product.aspx/{*ID}", "~/UrlRewrite/Approach1/Source.aspx"); // url mapping with * routing
}
so tell me my code is ok for Ignore few files type. why my js is not downloading.
my css file are in Styles folder, my js files are in Script folder etc. the Script & Styles folder in root. please guide me. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Phil Haack 的说法, http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx
As per Phil Haack, http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx
试试这个:
Try this:
您可以使用ResolveUrl
you can use ResolveUrl