ASP.NET MVC Subdomains

后端 未结 3 1435
渐次进展
渐次进展 2020-12-28 09:18

I have hosting and domain like that:

www.EXAMPLE.com

I\'ve created few subdomains like that:

www.PAGE1.EXAMPLE.com
www.PAGE         


        
3条回答
  •  失恋的感觉
    2020-12-28 10:05

    This is something I have wanted to do with ASP.NET MVC for a long time, but... This is not a concern that ASP.NET MVC is responsible for. This is a server concern (IIS). What you need to do is allow for wildcard subdomains on your IIS server and point them to your one application.

    Then you can do something like this with the HttpContext:

    HttpContext.Current.Request.Url.Host // user1.yourwebsite.com
    

    Then you just need to parse that and push it into your ASP.NET MVC app anyway you see fit:

    • Push it into Session
    • Update the current route data and push a value in
    • Etc....

    The choice is really up to you.

    Note: The downside here is that this makes local development increasingly difficult, so you might want to mock up a way to fake a subdomain in your application.

提交回复
热议问题