0

我正在为我的网站使用 url 路由结构。当我使用 url 路由(尤其是多段)时,我的 css 和 js 文件未加载。我使用了 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>
4

3 回答 3

2

试试这个:

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

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

你的 CSS 或 JS 文件路径应该以 " / " --> src="* / *Scripts/jquery.min.js" 开头

于 2013-02-11T05:04:57.923 回答
1

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

于 2012-08-10T10:05:35.250 回答
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(/.*)?"})
于 2014-08-21T15:53:00.523 回答