Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on SAML 2.0. I have forms authentication enabled in IDP. When a authentication request is made from SP to IDP, the request is authenticated using forms authentication in IDP.

IsAuthenticated is set to false in SP when i use FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie() to write a cookie but the same is set to true when i use FormsAuthentication.SetAuthCookie() to write a cookie.

What I have tried:

Following is the code that sets the cookie


C#
<pre lang="C#"> if (Membership.ValidateUser(model.UserName, model.Password))
      { 
        FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(GetSecurityTokenForFormsAuthentication(model.UserName));
      }

    private static SessionSecurityToken GetSecurityTokenForFormsAuthentication(string user)
            {
                var claims = new[]
                            {                            
                                new Claim(ClaimTypes.Name, user)
                };
    
                //TODO: Fetch roles from database based on appID
                var identity = new ClaimsIdentity(claims, &quot;Forms&quot;);
                var principal = new ClaimsPrincipal(identity);
                return new SessionSecurityToken(principal);
            }</pre>



After the cookie is set, the response is sent back to SP but the Context.IsAuthenticated is false in SP.

Whereas if i set the cookie using the following code and send the response to SP, then Context.IsAuthenticated is set true in SP

C#
<pre lang="C#"> if (Membership.ValidateUser(model.UserName, model.Password))
            { 
              FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
            }</pre>



Can anyone tell me why the Context.IsAuthenticated is set false when the cookie is set using FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie?
Posted

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900