views:

132

answers:

3

Is it possible or feasible to run a bunch off web sites off of only 1 code base?

For example I have 1 site that bases it's connection string off of the domain name or subdomain name. So, depending on what domain/subdomain is hitting the site the site returns content that is stored in a database specifically for that site.

What types of issues might occur from doing this? Specifically if doing this with asp.net.

+3  A: 

It's quite acceptable.

Just note that anyone can change the domain name that you may pick up (as long as you've configured a host header for it), so just make sure you don't go around making something like 'admin.foo' but relying only on that for security (you'd be mad though, obviously).

I see no problem with it.

Noon Silk
+3  A: 

It works and is proven. Se DotNetNuke for just 1 example of this.

Request come in. Regex/character matchthe domain name. Load settings for that domain (base path to images, css, config, pages etc etc) and off you go.

Jaimal Chohan
+1  A: 

The gotcha to look out for is if your application is both a) storing data in memory and b) using the same application space. So if, for example, you want to dish up two different blogs and you want the data to be resident in memory (if, say, your back-end store was XML and you didn't want to parse XML with every request) then you'll have to make sure that Asp.Net sees each call as a separate application (which can both point to the same file-system folder and thus uses the same files).

I ran into this exact situation when coding a multi-blog data provider for BlogEngine.Net. It uses a single code base to serve up different blogs based on the requested URL. However, since BlogEngine.Net carries its data in memory, the data provider won't work unless IIS is configured so that each blog is its own application.

Jacob Proffitt
What kind of calls to the "memory" where you making? Each page request would initialize itself as a request for a particular site and the code would execute within that initialization. If you had code bleed over you must have been using things like Session/Cache without properly keying the values to the particular site/request that they were associated with.
Chris Porter
It wasn't anything so fancy. Mostly, the base objects keep static List<object> collections. There's a static List<Post> and static List<Page> etc. Since these are static variables, they will remain until the process is cycled. This also means that the first call after a recycle carries a bit of a delay as *all* the data is read from the data store. I'm not a huge fan of the design, but it solved their problem with XML serialization on each call.
Jacob Proffitt