在 ASP.NET MVC3 中按域更改视图位置
我的域 domain1.com
带有别名 domain2.com
。
如何更改 domain2.com
的视图位置?
我想要默认页面:
- 对于domain1来说是
webhosting disk/Content/Views/Index.cshtml
- 对于domain2来说是
webhosting disk/Content/Views/Domain2/Index.cshtml
如何通过 global.asax 和 MVC 路由来实现这一点?
I have domain domain1.com
with an alias domain2.com
.
How I can change the location of views for domain2.com
?
I want the default pages:
- for domain1 to be
webhosting disk/Content/Views/Index.cshtml
- for domain2 to be
webhosting disk/Content/Views/Domain2/Index.cshtml
How can this be implemented via global.asax and an MVC route?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它们不能成为两个站点有什么原因吗?它们仍然可以使用主机头托管在具有相同 IP 的同一服务器上。
您可以扩展 Razor View Engine。这是将视图引擎扩展到 动态确定视图路径。
Is there a reason why they can't be two sites? They can still be hosted on the same server with same ip using hostheaders.
You can extend the Razor View Engine. This is an example extending the view engine to dynamically determining the view path.
看起来很简单:编写一个域感知
ViewEngine
。然而,我建议抽象出确定何时/如何将视图切换到它自己的界面的逻辑;这样,如果您决定切换 cookie 值而不是 URL 的视图,您可以轻松地做到这一点。Seems simple enough: write a domain aware
ViewEngine
. I'd recommend, however, abstracting out the logic of determining when/how to switch view into it's own interface; that way if you you decide to switch view on a cookie value, instead of URL, you can easily do so.