Platform: ASP.NET 4.0, MVC 4 RC, VS 2012
Update: I’ve answer my question, myself. Please see my answer post below
What I want to do:
I currently have a site called http://www.a.com which targets a specific customer segment. I want to create a variant called http://www.b.com which targets a different segment.
However, in the background, the technology and code for a and b will be the same for most parts, with only some pages / content different depending on whether the user is browsing using domain a or b. It makes absolutely no sense for me to create a new project for this purpose.
However, it’s not at all clear to me how I should implement http://www.b.com and it’s flow in MVC. How to render a different homepage when someone comes from http://www.b.com, goes through many pages which are the same as http://www.a.com but some rendered different depending on whether the URL is for a or b.
Some pointers, hints, examples greatly appreciated.
Update: I’ve answer my question, myself. Please see my answer post below
Here’s what I finally did
First, thanks to those that answered my post, you helped me think through what I could do. In the end, what I did was a fairly simple sequence of things. Here’s how:
I pointed my new domain http://www.b.com to my web host so typing http://www.b.com would point to the root of http://www.a.com (CNAME)
In my solution, I did the following
I have a BaseController that all controllers derive from, and in there I declared IsPageB
In the BaseController, I set its value depending on host
So in each controller, I check for IsPageB
For e.g. In the HomePage, I simply switched view depending on this variable
Inside the Views, I either use a ViewBag.IsPageB that I set in the controller, or if there’s no controller that’s generating the view, I simply set a local variable
And then generate markup based on this value.
And it all has worked fine so far, perhaps there’s a cleverer way to do this, but for my purpose where 90% of the underlying code is same where a or b, and some output changes, this is fine. But I’m always looking for cleaner ways. For e.g. is there some way I can access the IsPageB variable in a view without using ViewBag or attaching it to a model?