0

In my asp mvc application, I have an CustomRoute which inherited RouteBase (this class is used for handle sub domain url)

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

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

My RegisterRoutes method in Global.asax.cs file:

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 }
                );
}

My goal is to handle all of url which contain sub domain base on CustomRoute, for another url will use asp mvc default route. HOW TO? any help would be greatly appreciated

Other problem is: all of resource (action / css / image....) which contain sub domain or not, it absolutely process by CustomRoute first :-(

Thanks for reading to the end :-)

1 Answer 1

1

You can add your resources to the IgnoreRoute list

 routes.IgnoreRoute("/Content/CSS/{*pathInfo}");
 routes.IgnoreRoute("/Content/Images/{*pathInfo}");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for help me resolved the problem about resource file, but for the url like contoso.com/Home or contoso.com/Comment it still invoke the method GetVirtualPath() in CustomRoute class, I just want to invoke the GetVirtualPath() method for all url which contain sub domain :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.