以下是Custom RouteBase类
public class CustomRoutingBehaviour:RouteBase
{
string[] allowedUrl;
public CustomRoutingBehaviour(string[] url)
{
allowedUrl = url;
}
public override RouteData GetRouteData(HttpContextBase httpContext)
{
RouteData route = null;
string browsedurl = httpContext.Request.AppRelativeCurrentExecutionFilePath;
if(allowedUrl.Contains(browsedurl,StringComparer.OrdinalIgnoreCase))
{
route = new RouteData(this,new MvcRouteHandler());
route.Values.Add("controller","CustomiziedController");
route.Values.Add("action","Index");
route.Values.Add("BrowsedURL",browsedurl);
}
return route;
}
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
return null;
}
}
以下是路由配置:
routes.Add(new CustomRoutingBehaviour(new string[] { "~/Customizied/Index", "~/Customizied/Index1" }));
答案 0 :(得分:0)
我有完全相同的问题。我已经解决了在浏览器的url地址添加结尾斜杠( / )的问题。注意处理代码中的斜杠。您可以在 CustomRoutingBehaviour 类或子串 browsedurl 变量的ctor中传递的数组的每个网址上添加最终斜杠。 我不知道为什么会这样。