根据发布的域以不同方式呈现视图
Mypage.cshtml 有一个页面,有一个域“xxx.com”和一个子域“test.xxx.com”,当我在子域“test.xxx.com”中发布我的网站时,页面的标题显示不同的内容。它会是这样的:
@if (--Request.IsSubDomain("test")--)
{
<h1>Test page: Product</h1>
}
else
{
<h1>Product</h1>
}
Mypage.cshtml have a page and have a domain "xxx.com" and a subdomain "test.xxx.com" that when I publish my site in the subdomain "test.xxx.com" the title of the page shows something different. It would be something like:
@if (--Request.IsSubDomain("test")--)
{
<h1>Test page: Product</h1>
}
else
{
<h1>Product</h1>
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不希望在您的视图中出现此登录信息。我个人会将其移至自定义属性中或直接将逻辑包含在控制器中。
顺便问一下,问题是什么?
编辑:
您可以使用
Request.Url.Authority
来确定域。You would not want to have this login in your views. I personally would move this into a custom attribute or include the logic directly in your controllers.
By the way, what is the question?
Edit:
You could use
Request.Url.Authority
to determine the domain.我通常不建议使用
ViewBag
,但如果您仅想使用它来呈现标题,请从父控制器中子类化您的控制器,例如GeneralController< /code> 并根据域设置一个
ViewBag.Title
属性。一种替代方法是从包含类似逻辑的基本视图模型中对任何视图模型进行子类化。
然后,任何控制器和随后渲染的视图都将能够使用此 ViewBag.Title 属性。事实上,MVC3 开箱即用地包含
_Layout.cshtml
作为其默认布局(或母版页),该布局已在头部包含以下行:I don't normally recommend using
ViewBag
, but if you only want to use this to render a title, subclass your controllers from a parent controller say,GeneralController
and set aViewBag.Title
property there based on domain.One alternative to this is subclassing any view models from a base view model including similar logic.
Then, any controller and subsequently rendered views will be able to use this ViewBag.Title property. In fact, out of the box, MVC3 includes
_Layout.cshtml
as its default layout (or Master Page) that already contains the following line in the head: