To resolve this problem, make sure that at least one of the three configuration settings (cookie name, cookie path, and key) is different for each application that uses forms authentication.
Different Cookie Names
If you use different cookie names for each application, you ensure that forms authentication only retrieves a cookie according to the name that is configured for that application.
For example:
- Application1 uses the name authCookie1.
- Application2 uses the name authCookie2.
- A request is made to Application2.
- Forms authentication tries to retrieve authCookie2 from the HttpRequest.Cookies collection, even though the authCookie1 cookie exists.
When forms authentication does not find an authentication cookie with the name authCookie2, the user is redirected to the page that is specified in the loginUrl attribute for Application2.
Different Cookie Paths
If you use a different cookie path, you ensure that the authentication cookie is sent only to the application in which the cookie originated.
For example:
- Application1 uses the path /application1.
- Application2 uses the path /application2.
- Forms authentication authenticates to Application1.
- A request is made to Application2. The browser does not send the authentication cookie from Application1 to Application2 because the cookie can be sent only to Application1.
NOTE: The
path attribute is case sensitive. Therefore, if the you set the value of the
path attribute to /application1, and if the application name is Application1, the authentication cookie path is /application1.
When the user is authenticated and redirected, the browser does not send the cookie with the /application1 path to the Application1 application. Essentially, the authentication cookie is not part of the
HttpRequest.Cookies collection. As a result, the user is redirected to the page that is specified in the
loginUrl attribute, even after authentication.
Microsoft recommends that you confine forms authentication cookies to areas of the site that are protected by Secure Sockets Layer (SSL) encryption.
Different Keys
If different applications use different, explicit values for the
<machineKey> element, the encryption, the decryption, or the validation of the authentication cookie fails. As a result, the user is redirected to the page that is specified in the
loginUrl attribute for the application.
NOTE: Even in identical configurations, authorization rules still apply. In the examples to follow, if User1 is authenticated in Application1 and makes a request to Application2, the request is authenticated. However, because User1 is not one of the allowed users in the <authorization> section, the request is not authorized and is denied.
Web.config in Application1
<configuration>
<system.web>
<authorization>
<allow users="User1,User2,User3" />
<deny users="?" />
</authorization>
</system.web>
</configuration>
Web.config in Application2
<configuration>
<system.web>
<authorization>
<allow users="User4,User5,User6" />
<deny users="?" />
</authorization>
</system.web>
</configuration>