【问题标题】:How to add subdomain for Area in mvc?如何在 mvc 中为 Area 添加子域?
【发布时间】:2016-10-25 04:53:40
【问题描述】:

我有一个使用 asp.net MVC 的 Web 应用程序并且有多个区域:

  • 本地主机
  • localhost/admin/home/index
  • localhost/tech/home/index

如何为该区域添加子域?示例:

  • 本地主机
  • admin.localhost/home/index
  • admin.tech/home/index

【问题讨论】:

  • 修改MapRoute配置以包含子域模式,注意修改后的路由应放在默认路由之上。
  • 谢谢你的回复:),你能给我详细的例子吗?
  • 您想对子域使用重定向吗?我看到admin.localhost/home/index可能会重定向到localhost/admin/home/index,这需要重定向和URL重写。

标签: asp.net-mvc routes subdomain area


【解决方案1】:
// admin.localhost/home/index
    [RouteArea("Admin", Subdomain = "admin", AreaUrl="Home")]
    public class SubdomainWithAreaUrlController : Controller
    {

        public ActionResult Index()
        {
            return Content("");
        }
    }

【讨论】:

    猜你喜欢
    • 2021-11-24
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 2016-11-14
    • 1970-01-01
    相关资源
    最近更新 更多