Cross-Application Forms Authentication

I've seen some confusion about how and whether you can have a user who has been "Forms-Authenticated" on one application or site be able to go to or be redirected to another application or site (or the "same" application on a web farm, which is essentially the same situation) and not have to re-authenticate.

ASP.NET 2.0 sports a new Forms Auth property, "EnableCrossAppRedirects". This can be set in the Forms Authentication web.config node, e.g.,

...
enableCrossAppRedirects="true" />

The way this works is that the EnableCrossAppRedirects property is checked within the RedirectFromLoginPage method when the redirect URL does not point to a page in the current application. If EnableCrossAppRedirects is true, then the redirect is performed; if EnableCrossAppRedirects is false, the browser is redirected to the page defined in the DefaultUrl property.

However, this is not sufficient to get you to "First Base". The name, protection, path, validationKey, and decryptionKey attributes must all be identical across all applications. In addition, the encryption and validation keys and the encryption scheme used for cookie data must be exactly the same. If the settings do not match, cookies can't be shared, and cross-app authentication won't work.

Here is an example web.config snippet:



<configuration>
<system.web>
<authentication mode="Forms" >
<!-- The name, protection, and path attributes must match
exactly in each Web.config file. -->
<forms loginUrl="login.aspx"
name=".ASPXFORMSAUTH"
protection="All"
path="/"
timeout="30" />
</authentication>

<!-- Validation and decryption keys must exactly match and cannot
be set to "AutoGenerate". The validation algorithm must also
be the same. -->
<machineKey validationKey="C50B3C89CB21F4F1422FF158A5B42D0E8DB8CB5CDA1742572A487D940
1E3400267682B202B746511891C1BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE"
decryptionKey="8A9BE8FD67AF6979E7D20198CFEA50DD3D3799C77AF2B72F"
validation="SHA1" />
</system.web>
</configuration>


I wrote an article about this a long time ago, it' still valid today. There is also a sample page that will generate a machinekey element for you here.

Comments

  1. Anonymous8:59 AM

    Thanks a lot. This addressed and helped me out with the exact issue that I was having!

    ReplyDelete

Post a Comment

Popular posts from this blog

Some observations on Script Callbacks, "AJAX", "ATLAS" "AHAB" and where it's all going.

IE7 - Vista: "Internet Explorer has stopped Working"

FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX