我不确定您是否可以在一行中指定所有这些。另一种方法是您可以创建自定义路由约束并完全忽略这些文件夹/文件。
更新:
根据@Brent的反馈,检查pathinfo
比比较folder
.
public class IgnoreConstraint : IRouteConstraint
{
private readonly string[] _ignoreList;
public IgnoreConstraint(params string[] ignoreList)
{
_ignoreList = ignoreList;
}
public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName,
RouteValueDictionary values, RouteDirection routeDirection)
{
return _ignoreList.Contains(Path.GetExtension(values["pathinfo"].ToString()));
}
}
全球.asax.cs
routes.IgnoreRoute("{*pathInfo}", new { c =
new IgnoreConstraint(".js", ".css") });
routes.RouteExistingFiles = true;
==================================================== ===============================
以前的代码
public class IgnoreConstraint: IRouteConstraint
{
private readonly string[] _ignoreArray;
public IgnoreConstraint(params string[] ignoreArray)
{
_ignoreArray = ignoreArray;
}
public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName,
RouteValueDictionary values, RouteDirection routeDirection)
{
var folder = values["folder"].ToString().ToLower();
return _ignoreArray.Contains(folder);
}
}
在 Global.asax.cs
routes.IgnoreRoute("{folder}/{*pathInfo}", new { c =
new IgnoreConstraint("content", "script") });
routes.RouteExistingFiles = true;