Using ASP.NET Membership

Nov 26, 2013 at 11:24 AM
Edited Nov 26, 2013 at 11:25 AM
I have done what I think is correct for the ASP.NET Membership below to work and I can login to my main site and I can login through the nearforums using the same credentials but I always have to login a second time.

I am using IIS and have a application in the DefaultWebSite called Site I have placed another application under this called Forum. Both of the web.config files for these sites use the same forms authentication and the same Membership provider.

If I login into both and logout using the link in the forum I am logged out of both, so this is very close to being correct I will keep working at it but if you can see anything obvious please let me know.

From the Site Web.config
<authentication mode="Forms">
      <forms loginUrl="~/" timeout="2880" />
 <membership defaultProvider="DefaultMembershipProvider" userIsOnlineTimeWindow="20">
        <clear />
        <add name="DefaultMembershipProvider" 
             passwordAttemptWindow="10" />
From the Forum Web.config
<authentication  mode="Forms" />
    <membership defaultProvider="DefaultMembershipProvider">
        <add name="DefaultMembershipProvider"
             connectionStringName="DbContext" enablePasswordRetrieval="false" enablePasswordReset="true" 
             requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" 
             maxInvalidPasswordAttempts="30" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" 
             passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" />
ASP.NET Membership
If your website uses ASP.NET Membership, you can configure the same membership provider in the web.config file of the Nearforums site.
This method will avoid the need for explicit user log on actions (logging on mainsite will also log into Nearforums site). Remember to use the same machine key if you are using 2 different IIS websites.
Nov 26, 2013 at 11:39 AM
Mmmmm... weird!
It is probably due to the membership cookie. Use Firebug (cookies tab) or Chrome console (resources tab) to check the name and value of both cookie to see what's going on.
Nov 26, 2013 at 12:14 PM
I will look at that as it's worth knowing whats happening but I think I have sorted it now by adding the correct machineKey to both config files. If I find anything else to make what I did any clearer I will post it for others if they need it.