c# - How do i pass cookie value in multiple subdomain in sso mvc5 -


for url xyz.com(for first web application project): while log in user store information in cookie here in login page:

 formsauthenticationticket authticket = new formsauthenticationticket(                              1,                              serializemodel.useremail,                              datetime.now,                              datetime.now.addminutes(55),                              _rememberme,                              userdata);                      string encticket = formsauthentication.encrypt(authticket);                     httpcookie facookie = new httpcookie(formsauthentication.formscookiename, encticket);                     response.cookies.add(facookie); 

here global.asax:

    protected void application_postauthenticaterequest(object sender, eventargs e)     {         httpcookie authcookie = request.cookies[formsauthentication.formscookiename];          if (authcookie != null)         {             try             {                 formsauthenticationticket authticket = formsauthentication.decrypt(authcookie.value);                  javascriptserializer serializer = new javascriptserializer();                  customprincipalserializemodel serializemodel = serializer.deserialize<customprincipalserializemodel>(authticket.userdata);                  customprincipal newuser = new customprincipal(authticket.name);                 newuser.userid  = serializemodel.userid;                 newuser.firstname = serializemodel.firstname;                 newuser.lastname = serializemodel.lastname;                 newuser.profilepicture = serializemodel.profilepicture;                 newuser.usercode = serializemodel.usercode;                 newuser.useremail = serializemodel.useremail;                 newuser.usertype = serializemodel.usertype;                 newuser.fk_parent = serializemodel.fk_parent;                 newuser.companyid = serializemodel.companyid;                 newuser.issass = serializemodel.issass;                 newuser.commission = serializemodel.commission;                 newuser.commissionmanager = serializemodel.commissionmanager;                 newuser.isacount = serializemodel.isacount;                  httpcontext.current.user = newuser;             }             catch (exception ex)             {                 httpcontext.current.user = null;             }         }     }      interface icustomprincipal : iprincipal     {         int userid { get; set; }         string firstname { get; set; }         string lastname { get; set; }         string profilepicture { get; set; }         guid usercode { get; set; }         string useremail { get; set; }         int usertype { get; set; }         int fk_parent { get; set; }         string companyid { get; set; }         nullable<bool> issass { get; set; }         double? commission { get; set; }         double? commissionmanager { get; set; }         nullable<int> isacount { get; set; }     }      public class customprincipal : icustomprincipal     {         public iidentity identity { get; private set; }         public bool isinrole(string role) {             string inrole = string.empty;             inrole =enum.getname(typeof(usertype), usertype);              if (inrole == role)             {                 return true;             }             else             {                 return false;             }          }          public customprincipal(string email)         {             this.identity = new genericidentity(email);         }          public int userid { get; set; }         public string firstname { get; set; }         public string lastname { get; set; }         public string profilepicture { get; set; }         public guid usercode { get; set; }         public string useremail { get; set; }         public int usertype { get; set; }         public int fk_parent { get; set; }         public string companyid { get; set; }         public nullable<bool> issass { get; set; }         public double? commission { get; set; }         public double? commissionmanager { get; set; }         public nullable<int> isacount { get; set; }     }      public class customprincipalserializemodel     {         public int userid { get; set; }         public string firstname { get; set; }      } 

here sub domain of a.xyz.com(2nd web application project)(both project in mvc5 c#. here global.asax:

 protected void application_postauthenticaterequest(object sender, eventargs e)     {         httpcookie authcookie = request.cookies[formsauthentication.formscookiename];          if (authcookie != null)         {             try             {                 formsauthenticationticket authticket = formsauthentication.decrypt(authcookie.value);                  javascriptserializer serializer = new javascriptserializer();                  customprincipalserializemodel serializemodel = serializer.deserialize<customprincipalserializemodel>(authticket.userdata);                  customprincipal newuser = new customprincipal(authticket.name);                 newuser.userid = serializemodel.userid;                 newuser.firstname = serializemodel.firstname;                 newuser.lastname = serializemodel.lastname;                 newuser.profilepicture = serializemodel.profilepicture;                 newuser.usercode = serializemodel.usercode;                 newuser.useremail = serializemodel.useremail;                 newuser.usertype = serializemodel.usertype;                 newuser.fk_parent = serializemodel.fk_parent;                 newuser.companyid = serializemodel.companyid;                 newuser.issass = serializemodel.issass;                 newuser.commission = serializemodel.commission;                 newuser.commissionmanager = serializemodel.commissionmanager;                 newuser.isacount = serializemodel.isacount;                  httpcontext.current.user = newuser;             }             catch (exception ex)             {                 httpcontext.current.user = null;             }         }     }      interface icustomprincipal : iprincipal     {         int userid { get; set; }         string firstname { get; set; }         string lastname { get; set; }         string profilepicture { get; set; }         guid usercode { get; set; }         string useremail { get; set; }         int usertype { get; set; }         int fk_parent { get; set; }         string companyid { get; set; }         nullable<bool> issass { get; set; }         double? commission { get; set; }         double? commissionmanager { get; set; }         nullable<int> isacount { get; set; }     }      public class customprincipal : icustomprincipal     {         public iidentity identity { get; private set; }         public bool isinrole(string role)         {             string inrole = string.empty;             inrole = enum.getname(typeof(usertype), usertype);              if (inrole == role)             {                 return true;             }             else             {                 return false;             }          }          public customprincipal(string email)         {             this.identity = new genericidentity(email);         }          public int userid { get; set; }         public string firstname { get; set; }         public string lastname { get; set; }         public string profilepicture { get; set; }         public guid usercode { get; set; }         public string useremail { get; set; }         public int usertype { get; set; }         public int fk_parent { get; set; }         public string companyid { get; set; }         public nullable<bool> issass { get; set; }         public double? commission { get; set; }         public double? commissionmanager { get; set; }         public nullable<int> isacount { get; set; }     }      public class customprincipalserializemodel     {         public int userid { get; set; }         public string firstname { get; set; }         public string lastname { get; set; }         public string profilepicture { get; set; }         public guid usercode { get; set; }         public string useremail { get; set; }         public int usertype { get; set; }         public int fk_parent { get; set; }         public string companyid { get; set; }         public nullable<bool> issass { get; set; }         public double? commission { get; set; }         public double? commissionmanager { get; set; }         public nullable<int> isacount { get; set; }     } 

but issue in 2nd subdomain getting null value always.here store value , need validate in 2nd sudomain.in 2nd subdomain global.asax getting null value in authcookie always.

so how resolved??

i'm not sure if work, can try configure web.config on way:

<forms name="cookiename" loginurl="~/account/logon" timeout="2880" requiressl="false" slidingexpiration="false" domain="xyz.com" /> 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -