在我的 ASP.NET MVC 应用程序中为不同城市创建子域
我正在学习 .NET MVC 2,想知道如何为我存储在表中的城市列表创建子域。如果当我将城市添加到表中时以某种方式动态创建它们,那就太好了。
例如:
- seatle.mysite.com
- calgary.mysite.com
- orlando.mysite.com
我希望它能够在我的本地“开发”环境(Windows 7、IIS 7)以及我的实时站点(共享托管)中工作,无限子域)。
I'm learning .NET MVC 2 and would like to know how I could go about creating sub-domains for a list of cities that I have stored in a table. It would be nice if they were somehow created dynamically as I add cities to the table.
For Example:
- seatle.mysite.com
- calgary.mysite.com
- orlando.mysite.com
I'd like for it to work in my local "Dev" environment (windows 7, IIS 7) as well as on my live site (shared hosting, unlimited sub-domains).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在 DNS 上创建子域。从技术上讲,您可以将其编程到 Application_Start 中,但您确实应该弄清楚您将拥有什么列表,然后只需完成创建它们一次的工作。
或者,查看您的 DNS 和网络主机是否可以使用通配符域,以便 *.domainname.com 将转到您的网站。
完成此操作后,Maarten Balliauw 的博客有一篇关于如何路由子域的文章:
http://blog.maartenballiauw.be/post /2009/05/20/ASPNET-MVC-Domain-Routing.aspx
You'll have to create your subdomains on your DNS. Technically, you could program this into the Application_Start, but you really should figure out what list you will have and then just do the job to create them once.
Alternatively, see if your DNS and webhost can do wildcard domains so that *.domainname.com will go to your website.
After you do that, Maarten Balliauw's blog has an article on how to route subdomains:
http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx