简体   繁体   中英

Best practice for loading different themes or css files for different users in ASP.NET MVC

There are 2 questions:

  1. How to do the routing for different customers under same domain eg For customer A the url looks like: http://cusA.mydomain.com For customer B the url looks like: http://cusB.mydomain.com

  2. And according to different url(the above urls) to load different themes.

For question 1: I know we have sub-domain concept which talking about something more like : www.mydomain.com/cusA and www.mydomain.com/cusB. So I don't know whether it is capable of doing the sub-domain in front of mydomain

For question 2: If the question 1 gets solved, then I think I could read and parse the url and loading different themes according to the cusA or cusB part by using ASP.NET MVC theme stuff.

Could anybody provide some thoughts and technologies to use in my case?

Thank you.

Update:

Tried to use "Request.ApplicationPath" but doesn't work.

Here is the code

<h2>Site 2 Home Page</h2>

<a href="/Home/Contact">Go to Contact</a>
<label>The Application Path is @Request.ApplicationPath.Substring(1)</label>

My answer is not necessarily best practice, but rather how we have approached it in our product.

We have multiple sites running of the same application binaries, but each in a different application pool on the server. Each web-share has a config- and CSS file corresponding to the name of the share. We then use the config- and CSS files based on the Application's name on the server (ie Request.ApplicationPath).

In your case, you would have a web-share named CusA and another named CusB. You would have CSS files also named CusA.css and CusB.css respectively. You can then just include the CSS file based on the name of the application...

An example of including the stylesheet might be as follows:

<link href="<%=Request.ApplicationPath.Substring(1)%>.css" type="text/css" rel="stylesheet" />

That will link to "CusB.css" if the web-share's name is "CusB". The above snippet needs to be included in your view as a style include, but the view engine you use would obviously influence the syntax a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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