How do I ignore routing for few files type asp.net 4.0
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/So开发者_Go百科urce.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
As per Phil Haack, http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx
RouteTable.Routes.IgnoreRoute("{*alljs}", new {alljs=@".*\.js(/.*)?"});
RouteTable.Routes.IgnoreRoute("{*allpng}", new {allpng=@".*\.png(/.*)?"});
RouteTable.Routes.IgnoreRoute("{*allcss}", new {allcss=@".*\.css(/.*)?"});
Try this:
Routes.IgnoreRoute("{file}.js");
Routes.IgnoreRoute("{file}.css");
Routes.IgnoreRoute("{file}.png");
you can use ResolveUrl
<script type="text/javascript" src='<%= ResolveUrl("~/path to script ")%>'></script>
精彩评论