首页 > 解决方案 > 如何在 asp.net mvc 中有通配符子域

问题描述

我想在我的项目中拥有动态通配符子域。我希望每个提供商都有特殊的子域。例如,provider1.mydomain.com 更改为 mydomain.com/provider1,我想将 provider1 作为参数传递给我的操作。

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

如何在我的项目中执行此操作以及如何在 localhost 中执行此操作?

标签: asp.net-mvcwildcard-subdomain

解决方案


将此代码添加到 App_start 文件夹中的 RouteConfig 中:

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

推荐阅读