1

I need to be able to serve different versions of my whole site per client. Certainly beta vs production but it would be nice to serve one or two prior production versions. Client customization is encouraged and I don't wish to force all clients to follow the (anticipated) pace of development.

Which version to serve is stored in the db.

From what Ive read so far a custom view engine may be the most straightforward way to accomplish this but before heading down this road I would welcome any advice and comment.

Thanks for insight! Eric

EDIT: It isn't just the views that are different; controllers, master pages, images, CSS...

Eric Nelson
  • 763
  • 1
  • 8
  • 17
  • 1
    I went down the custom view engine route: http://stackoverflow.com/questions/9838766/implementing-a-custom-razorviewengine – Liam Sep 03 '12 at 12:55
  • Why not just deploy two different sites? – Tomas Jansson Sep 03 '12 at 12:59
  • @TomasJansson because I'd like it to be invisible to clients' customers. Otherwise, multiple sites I think might be simpler. – Eric Nelson Sep 03 '12 at 13:06
  • @Liam if you don't mind sharing, what was your folder structure on the server. Also, how did you map that to projects on your development machine & source control? – Eric Nelson Sep 03 '12 at 19:03
  • And why can't you achieve that with two different sites? Just don't deploy the beta so it is visible. For me it seems like you have some strange setup in how you manage your code and deploy your builds. What branches do you have in your source control? Where do you take your releases from? – Tomas Jansson Sep 04 '12 at 07:07
  • @tomas we generally take a branch for each release. We use a numbered release system. Both brands get a release at the same time. We don't want two different sites, because the controllers and models are the same. It's only the views that alter. If we used source control to manage this we'd soon end up in a pile of merges and cross merges! – Liam Sep 04 '12 at 08:00
  • @Eric, added an answer with more detail... – Liam Sep 04 '12 at 08:07
  • 1
    @Liam, If you read the Edit last in the question you see that everything is different, not just the views. – Tomas Jansson Sep 04 '12 at 10:18
  • Well thats new! If everything's different, create two sites? Why wouldn't you? – Liam Sep 04 '12 at 10:22
  • @TomasJansson I think the best may be to deploy different sites; however I'm puzzled how to route to them. Joocer suggested using a URL rewriter based on a cookie but I'm wondering if that's sufficiently robust (i.e. what if user has cookies disabled). – Eric Nelson Sep 10 '12 at 03:42

2 Answers2

1

If the rules regarding which version is displayed to which user, I'm guessing they need to authenticate first. If that's the case you'll have opportunity to set a cookie on the user.

I would probably set a cookie on authentication that determines which version to show the user and then use a URL Rewriter like IIRF to direct requests with that cookie set to the beta version of the site.

Has the added benefit of users being able to opt back to the production site if they have issues with the beta.

joocer
  • 1,111
  • 1
  • 7
  • 11
  • I thought I would just store which version in the DB. is there an advantage to doing it with cookies? – Eric Nelson Sep 03 '12 at 19:07
  • The advantage would be that you could deploy two versions of the site site by side, all users authenticate on one site, the DB still says which site they should be served by once signed in and then a URL rewriter could read the cookie so users are served the correct pages with the process being invisible to them – joocer Sep 03 '12 at 19:16
  • is there a way to make this work even if the user has cookies disabled? For example, can the URL rewriter see the user's identity and look up which version to serve? – Eric Nelson Sep 10 '12 at 03:38
  • @EricNelson the go-to solution is cookies is disabled is to put the data in the URL, but what you'd end up with is a complex solution to just having two sites with distinct URLs. Everything else is clumsy like redirection based on IP, referrer, user-agent. – joocer Sep 12 '12 at 19:40
1

I went down the view engine route How do I implement a custom RazorViewEngine to find views in non-standard locations?

Basically it's pretty stright forward, we have the same controllers models, etc. All the code is shared. The rendering of the views though is based on a "brand". So the view engine is clever enough to say if I'm brand A then the view will live in {standard view location}/brand/viewname.

It's hierachical though so if the view is in the branded folder it uses that one, else it falls back to the default location. It's basically an extension of the standard model used by MVC to find the location of the view source.

Community
  • 1
  • 1
Liam
  • 27,717
  • 28
  • 128
  • 190