Can I run multiple websites under a single membership database?

随声附和 提交于 2020-01-05 05:41:07

问题


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/folders, not on separate URLs.

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

Thanks in advance Al


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/2996564/can-i-run-multiple-websites-under-a-single-membership-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!