Can Areas in an ASP.NET MVC 2 application map to a subdomain?

后端 未结 4 1492
攒了一身酷
攒了一身酷 2021-02-04 03:10

Is there a way to map the Areas within an ASP.NET MVC 2 application to subdomains such as

movies.example.com/Theater/View/2

instead of

4条回答
  •  时光取名叫无心
    2021-02-04 03:36

    Areas are not directly related to routing, so your question becomes "does routing support subdomains?"

    The answer to that is unfortunately that there is no built-in support for this.

    However, the good news is that many people have tried and found success with custom code that builds on top of routing:

    • Is it possible to make an ASP.NET MVC route based on a subdomain?
    • Asp.net 3.5 Sp1 Sub-Domain routing?
    • And many others

    If you figure out how to route subdomains without areas then doing it with areas should be no more difficult. Go to your area registration context and use whatever technique you choose inside there. Areas are just a way to group together controllers and views - they don't have very much intrinsic meaning to ASP.NET MVC itself (they do a little bit, but not a lot).

提交回复
热议问题