Routes.Ignore不工作

时间:2012-08-10 09:31:37

标签: asp.net routing url-routing

我正在为我的网站使用url路由结构。当我使用url路由(特别是多段)我的css和js文件没有load.i使用Route.Ignor但不能正常工作。

void RouteMap(RouteCollection route)
{
    route.RouteExistingFiles = false;
    route.Ignore("{resource}.axd/{*pathInfo}"); //Not work
    routes.Ignore("{resource}.css/{*pathInfo}"); //Not work
    routes.Ignore("Styles/{*pathInfo}"); //Not work
    routes.Ignore("Styles/"); //Not work

    route.MapPageRoute("", "Guide", "~/Guide.aspx");
    route.MapPageRoute("", "Guide/{key}", "~/Guide.aspx");
    route.MapPageRoute("", "Search/{key}", "~/Search.aspx");
}

void Application_Start(object sender, EventArgs e)
{
    RouteMap(RouteTable.Routes);
}

<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/jquery.min.js" type="text/javascript"></script>

3 个答案:

答案 0 :(得分:2)

试试这个:

<link href="/Styles/Site.css" rel="stylesheet" type="text/css" />

<script src="/Scripts/jquery.min.js" type="text/javascript"></script>

你应该用“/” - &gt;开始你的CSS或JS文件路径SRC = “* / *脚本/ jquery.min.js”

答案 1 :(得分:1)

如果使用经典模式,请尝试使用IIS集成应用程序池(用于由.NET运行时处理的css文件)。

答案 2 :(得分:0)

colRoutes.RouteExistingFiles = False

colRoutes.Ignore("{*allaxd}", New With {.allaxd = ".*\.axd(/.*)?"})
colRoutes.Ignore("{*allaspx}", New With {.allaspx = ".*\.aspx(/.*)?"})
colRoutes.Ignore("{*allascx}", New With {.allascx = ".*\.ascx(/.*)?"})
colRoutes.Ignore("{*allashx}", New With {.allashx = ".*\.ashx(/.*)?"})
colRoutes.Ignore("{*allhtm}", New With {.allhtm = ".*\.htm(/.*)?"})
colRoutes.Ignore("{*allhtml}", New With {.allhtml = ".*\.html(/.*)?"})
colRoutes.Ignore("{*allcss}", New With {.allcss = ".*\.css(/.*)?"})
colRoutes.Ignore("{*alljs}", New With {.alljs = ".*\.js(/.*)?"})
colRoutes.Ignore("{*allpng}", New With {.allpng = ".*\.png(/.*)?"})
colRoutes.Ignore("{*allgif}", New With {.allgif = ".*\.gif(/.*)?"})
colRoutes.Ignore("{*alljpg}", New With {.alljpg = ".*\.jpg(/.*)?"})
colRoutes.Ignore("{*alltif}", New With {.alltif = ".*\.tif(/.*)?"})
colRoutes.Ignore("{*allico}", New With {.allico = ".*\.ico(/.*)?"})
colRoutes.Ignore("{*allttf}", New With {.allttf = ".*\.ttf(/.*)?"})
colRoutes.Ignore("{*alleot}", New With {.alleot = ".*\.eot(/.*)?"})
colRoutes.Ignore("{*allsvg}", New With {.allsvg = ".*\.svg(/.*)?"})
colRoutes.Ignore("{*allwoff}", New With {.allwoff = ".*\.woff(/.*)?"})