I have 2 asp.net mvc applications running in a server using different virtual directory, for example http://myserver/app1/ and http://myserver/app2/ and each of them is using their own authentication (Forms Auth). Here's the problem a user using app1 and the page directs them to log into app1, after that they open a new tab to use app2 and log into app2, but when user try to return to app1 the page direct them to log in page again. Is this the normal behavior, and how to fix this so that app1 and app2 can be used from a single browser concurrently.
-
Are both applications using the same database? – Derek Tomes Feb 04 '15 at 03:09
-
@DerekTomes Yes they are, and they should. If that's the cause is there any explanation or how to solve it? – Marcel Daryanto Feb 04 '15 at 03:12
-
possible duplicate of [Forms Authentication across Sub-Domains](http://stackoverflow.com/questions/608120/forms-authentication-across-sub-domains) – Derek Tomes Feb 04 '15 at 03:38
-
Try this: http://stackoverflow.com/questions/608120/forms-authentication-across-sub-domains – Derek Tomes Feb 04 '15 at 03:38
2 Answers
Is this the normal behavior?
Yes, it is a normal behavior. By default, FormsAuthentication.CookieDomain is empty string which means http://myserver.
Basically, app2 cookie overrides app1 cookie, and vice versa.
how to fix this so that app1 and app2 can be used from a single browser concurrently.
You need to set cookie domain explicitly in each web.config.
For example, for App1
<authentication mode="Forms">
<forms ... domain="http://myserver/app1/" />
</authentication>

- 61,100
- 13
- 102
- 181
Is this the normal behavior?
Yes, Since they are two separate applications running with their own resources.
Solution: You have to configure machine keys in web.config in both applications so they match hence they'll be able to decode data that the other party generated. And that's the whole trick. The MSDN Article Around Forms Authentication Across Applications explains this in great detail including how to generate those keys.

- 18,024
- 7
- 45
- 70