views:

109

answers:

2

Hi all,

I'm trying to plan a series of websites that all share many of the resources such as css/jscript/images/content etc. For this reason I wanted to run all of the websites under the same application and IIS profile, but depending on the URL being used change the masterpage and theme/skin.

The ASP.NET membership database seems as if it was designed with this goal in mind because it allows you to setup multiple applications, however I believe the purpose for which this was built was to allow applications to be run under virtual directories/fodlers, not on seperate urls.

Is it possible to map a url to a particular application?

Thanks in advance Al

A: 

The easiest solution would be to include the style sheet depending on what URL the page is being executed on, using:

Request.ServerVariables("SERVER_NAME")

IE (pseudo):

if Request.ServerVariables("SERVER_NAME") = "http://www.domain1.com" then
  include stylesheet1
else
  include stylesheet2
end if

You would need to find a function to extract the domain name from the URL so it works well.

Tom Gullen
A: 

Yes it is possible to do this. In your configuration, use the applicationName for your providers. This way, all of the data will be saved in the same database, but kept separate by the Application Id that you will find in most of the tables.

One possibility for your shared resources can be to put them in just one location and you can point to that location from your other site by using a full url to the file in the first location.

Another possibility is to host one app in a virtual directory in the same domain, although you can get into some interesting issues with web.config inheritance doing this. It would help if you show your intended domain naming for the two applications.

In one application: web.config 1:

<roleManager enabled="true">
    <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" applicationName="/ApplicationOne"
            ...add other properties here as standard
     />
    </providers>
</roleManager>
<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" applicationName="/ApplicationOne"
            ...add other properties here as standard
         />
    </providers>
</membership>

In your other application: web.config 2:

<roleManager enabled="true">
    <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" applicationName="/ApplicationTwo"
            ...add other properties here as standard
     />
    </providers>
</roleManager>
<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" applicationName="/ApplicationTwo"
            ... add other properties here as standard
         />
    </providers>
</membership>
Daniel Dyson