7

I've set up two ASP.NET applications on a machine, their web.config files contain the same applicationName value in AspNetSqlMembershipProvider item so they share users and roles.

The problem sequence is:

  • user logs into application A,
  • opens new tab in a browser
  • logs into application B,
  • his login in application A is signed out

and vice versa.

Should I use a different approach to sharing login information between two applications?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Axarydax
  • 16,353
  • 21
  • 92
  • 151
  • Do you use the same base url for both applications ? for example www.site.com/app1 is www.site.com/app2, or www.othersite.com/ – Aristos Mar 22 '10 at 10:59

2 Answers2

15

The problem you have is because the same cookie used, for authenticate the 2 different logins.

The solution from what I understand is to give different cookie name on the different logins, so the one cookie, not overwrite the other one.

Probably the solution is on web.config.

On Config

Change the name value, to something different on your 2 apps, if you have the same domain and run on different directory/apps, or change also the domain value that used also to keep the cookie.

<authentication mode="Forms">
 <forms name=".CookieSuffix" domain="yoururl.com" ... />
</authentication>    

For example, on the 2 diferent web.config on your apps, place
on app 1: name=".app1"
on app 2: name=".app2"

Or on app 1: domain="app1.yoururl.com"
on app 2: domain="app2.yoururl.com"
if you separate your apps, base on url, or even try some similar aproces.

The cookie is keep, using the cookie name on the domain name, so this is the 2 values that you must try to seperate them.

Details on Form setup can be found here: http://msdn.microsoft.com/en-us/library/aa480476.aspx

Manual login

If you have the oportunity to make manual login the solution is on this function

FormsAuthentication.GetAuthCookie(cUserName, false, "cookiePath");
FormsAuthentication.SetAuthCookie(cUserName, false, "cookiePath");

You only need to use a diferent cookiePath, but, you must change many points on your program, and capture the process login, logout and Authenticate.

Hope this help you.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • This worked well for us in a situation where we had side by side TEST and DEV web sites on the same server but they pointed to different aspnetdbs and we wanted to force re-authentication when a new tab was opened (which didn't happen). Typically you'd be logged into the DEV url and you'd open a new tab and copy paste the url change it to TEST URL (same web server, similar url) and you'd be logged in automatically on the second tab (not ideal in our case). Setting one name=".TEST" and setting the other name=".DEV" solved our issue. Note: we didn't need to set domain in our case. – Jeff Mergler Jun 07 '17 at 15:55
0

You should check out this tutorial.

Scroll down to the section titled Partitioning the User Store Into Applications. It says there that you can use the same user store for multiple applications.

Theresa
  • 3,515
  • 10
  • 42
  • 47
  • Thanks, my user store works fine with multiple applications, the problem is that logging in application A logs out the user in application B. – Axarydax Mar 16 '10 at 14:09