user1519979
user1519979

Reputation: 1874

FormsAuthenticationTicket - userdata is empty on one App (CrossApp Form Auth)

How i use FormsAuthentication:

app1.example.com:

app2.example.com:

For the login i do following:

FormsAuthentication.SetAuthCookie(
        userId.ToString(), false);

FormsAuthenticationTicket ticket1 =
    new FormsAuthenticationTicket(
        1,                                  
        userId.ToString(),  
        DateTime.Now,                       
        DateTime.Now.AddMinutes(20),        
        false,   
        sessionid                              // sessionid

        );
HttpCookie cookie1 = new HttpCookie(
    FormsAuthentication.FormsCookieName,
    FormsAuthentication.Encrypt(ticket1));
HttpContext.Current.Response.Cookies.Add(cookie1);

string returnUrl = HttpContext.Current.Request["redirect"] == null ? "app1.example.com" : HttpContext.Current.Request["redirect"];

    HttpContext.Current.Response.Redirect(returnUrl);

On each application i have to read out my custom "sessionid" from the AuthCookie. On App2 i get the correct id and on the App1, which contains the login page, i don't (it's empty).

Does anyone have an idea how it comes?

Here's my code for reading the userdata out:

 HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);

All apps are running on Asp.Net 4.5.2

Thanks in advance!

Upvotes: 0

Views: 474

Answers (0)

Related Questions