Search code examples
asp.net-mvcwildcard-subdomain

how can I have wildcard subdomain in asp.net mvc


I want to have dynamic wiladcard subdomain in my project.I want each provider have special subdomain. e.g provider1.mydomain.com change to mydomain.com/provider1 and I want pass provider1 as parameter to my action.

public ActionResult Details(string provider1){
   //there is some code for show provider details     
   return view();
   }

How can I do this in my project and How can I do this in localhost?


Solution

  • Add this code to RouteConfig in App_start Folder :

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