简体   繁体   English

MVC动态更改传入主机域上的stylebundle

[英]mvc dynamically change stylebundle on incoming host domain

Been trying to work through this problem for a bit now. 一直在尝试解决这个问题。 It is MVC4 C# 这是MVC4 C#

The jist: I require change the entire site layout based which domain contacted the server. 吉斯特:我需要根据与服务器联系的域来更改整个网站布局。

The details: My initial thoughts were that if someone entered on "bobsdiner.com" vs "susansCafe.com" that i would be able to put some logic in app_start to get the host name and then set the stylebundle to the correct stylesheet (additionally setting a _layout view would be fantastic as well). 详细信息:我最初的想法是,如果有人在“ bobsdiner.com”和“ susansCafe.com”上输入,我将能够在app_start中添加一些逻辑以获取主机名,然后将stylebundle设置为正确的样式表(另外设置_layout视图也很不错)。 I have found out that IIS7 will not allow access to the request object in app_start any longer. 我发现IIS7将不再允许访问app_start中的请求对象。 I am a bit of a loss of where to go next where i can have a central code section instead of changing this for every controller (i have about 15 of them). 我有点不知所措,下一步我可以拥有一个中央代码段,而不是为每个控制器更改它(我大约有15个)。 In addition to all this i would like to be able to access the db with the host name as i do have a table that contains domain names and the stylesheet names. 除了所有这些,我希望能够使用主机名访问数据库,因为我确实有一个包含域名和样式表名称的表。

any ideas are greatly appreciated! 任何想法都将不胜感激!

I would forgo trying to change the style bundle and re-purpose the context switcher. 我会放弃尝试更改样式包并重新使用上下文切换器。

in the app start of the global asax, you can do something like this 在全局asax的应用程序开始中,您可以执行以下操作

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Bobs")
        {
            ContextCondition = ctx => ctx.Request.Url.Host.Contains("bobsdiner")
        });

So if you make your site look like susanscafe using the _layout.cshtml, and then create a bobs diner version by using _layout.Bobs.cshtml. 因此,如果您使用_layout.cshtml使网站看起来像susanscafe,然后使用_layout.Bobs.cshtml创建bobs diner版本。 you can specify the different look and feel there to get the effect you want. 您可以在此处指定不同的外观以获得所需的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM