2012-11-15 43 views
0

在我的ASP MVC應用程序,我有繼承RouteBase的CustomRoute(這個類是用於把手子域 URL)ASP MVC創建CustomRoute子域?

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

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

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

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默認路由。如何?任何幫助將不勝感激

另一個問題是:所有資源(動作/ CSS /圖像....),它包含子域或沒有,這是絕對的CustomRoute過程首先:-(

感謝的閱讀到底:-)

回答

1

您可以添加資源,IgnoreRoute列表

routes.IgnoreRoute("/Content/CSS/{*pathInfo}"); 
routes.IgnoreRoute("/Content/Images/{*pathInfo}"); 
+0

感謝您的幫助我解決了有關資源文件中的問題,但對於像http://contoso.com/網址主頁或http://contoso.com/Comment它仍然調用GetVirtu方法CustomRoute類中的alPath(),我只想爲包含子域的所有url調用GetVirtualPath()方法:-( –