Click here to Skip to main content
13,260,330 members (44,295 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


17 bookmarked
Posted 10 Aug 2012

Sharing Authentication Cookie between two ASP.NET Applications

, 11 Sep 2012
Rate this:
Please Sign up or sign in to vote.
Sharing authentication information between applications.


The objective is to explain how to share the same Authentication cookie information between two ASP.NET applications.

The Approach

Assume that there are two applications and wants to share the cookie between these applications below are the settings required to share authentication ticket(cookie) across applications.

Step I

Need to set the enableCrossAppRedirects, domain, and requireSSL in both the application config files, under forms section.

First, the application config file.

<authentication mode="Forms">
  <forms name="FormsAuthentication" path="/" loginUrl="Login.aspx"

     defaultUrl="Home.aspx" timeout="1000" cookieless="UseCookies"  

     enableCrossAppRedirects ="true" domain="" 


A machine key is required to decrypt the ticket:



     validationKey="6FA5B7DB89076816248243B8FD7336CCA360DAF8" />

The second application config file should be,

<authentication mode="Forms">
  <forms name="FormsAuthentication" path="/" loginUrl="login.aspx"

    defaultUrl="PropertyList.aspx" timeout="1000"

    cookieless="UseCookies" enableCrossAppRedirects="true"

    domain="" requireSSL="false"/>

And the Machine Key should be:



    validationKey="6FA5B7DB89076816248243B8FD7336CCA360DAF8" />

Make sure that you are using the same machine keys in both the applications. 

Step II

The first application needs to use the following code while redirecting to the second application.

public static string FormatRedirectUrl(string redirectUrl)
    HttpContext c = HttpContext.Current;
    //Don’t append the forms auth ticket for unauthenticated users 
    //for users authenticated with a different mechanism
    if (!c.User.Identity.IsAuthenticated ||
        !(c.User.Identity.AuthenticationType == "Forms"))
        return redirectUrl;
    //Determine if we need to append to an existing query-string or
    string qsSpacer;

    if (redirectUrl.IndexOf('?') > 0)
        qsSpacer = "&";
        qsSpacer = "?";
    //Build the new redirect URL. Assuming that currently using
    //forms authentication. Change the below FormsIdentity if required.
    string newRedirectUrl;
    string newRedirectUrl;
    FormsIdentity fi = (FormsIdentity)c.User.Identity;
    newRedirectUrl = redirectUrl + qsSpacer +
    FormsAuthentication.FormsCookieName + "=" +
    return newRedirectUrl;

The redirectUrl in the above code should be /<WebPages>/SecondAppPage.aspx, then only can it hold  the cookies along with the Redirect call. 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Milan Mathew
United States United States
A coder from india. Specialized in Microsoft Technologies (ASP.NET, C#, WPF, MVVM, WCF, Biztalk)

Additional experience in Optical Character recognition (Acorde (Kofax) & Oracle IPM 7.7)

You may also be interested in...


Comments and Discussions

QuestionIs posible to implement this solution in mvc? Pin
Member 123361921-Jun-17 10:15
memberMember 123361921-Jun-17 10:15 
QuestionFramework 4.5.2 Pin
bispenho9-Oct-14 8:11
memberbispenho9-Oct-14 8:11 
Questionsecond step Pin
MapGuy1112-Feb-13 7:30
memberMapGuy1112-Feb-13 7:30 
AnswerRe: second step Pin
Milan Mathew8-Mar-13 3:55
memberMilan Mathew8-Mar-13 3:55 
GeneralMy vote of 5 Pin
christhomps27-Oct-12 23:44
memberchristhomps27-Oct-12 23:44 
QuestionNice Article Pin
christhomps11-Sep-12 21:26
memberchristhomps11-Sep-12 21:26 
AnswerRe: Nice Article Pin
Milan Mathew11-Sep-12 21:29
memberMilan Mathew11-Sep-12 21:29 
GeneralMy vote of 5 Pin
christhomps11-Sep-12 21:26
memberchristhomps11-Sep-12 21:26 
A very nice article. I'll try this tip today and let you know my additional findings.
GeneralRe: My vote of 5 Pin
Milan Mathew11-Sep-12 21:31
memberMilan Mathew11-Sep-12 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 11 Sep 2012
Article Copyright 2012 by Milan Mathew
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid