0

在我的 asp mvc 应用程序中,我有一个继承 RouteBase 的 CustomRoute(此类用于处理子域url)

public class CustomRoute : RouteBase
{
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
             // do something
        }

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            // do something
        }
}

我在 Global.asax.cs 文件中的 RegisterRoutes 方法:

public static void RegisterRoutes(RouteCollection routes)
{
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

      routes.Add(new CustomRoute());

      routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
}

我的目标是处理所有包含基于 CustomRoute 的子域的 url,因为另一个 url 将使用 asp mvc 默认路由。如何?任何帮助将不胜感激

其他问题是:所有包含子域的资源(action / css / image ....),它绝对首先由CustomRoute处理:-(

感谢您阅读到最后:-)

4

1 回答 1

1

您可以将资源添加到IgnoreRoute列表中

 routes.IgnoreRoute("/Content/CSS/{*pathInfo}");
 routes.IgnoreRoute("/Content/Images/{*pathInfo}");
于 2012-11-15T17:07:05.033 回答