2016-03-24 22 views
0

我有一個應用程序,使用System.Security.Claims和用戶登錄後說,www.mysite.co.uk,然後將url更改爲mysite.co.uk,他們已註銷。從www更改時,C#ClaimsIdentity(System.Security.Claims)不會持久。路由

我該如何阻止他們被註銷並堅持在兩個url之間登錄?

這是當前的代碼登錄的用戶,他們已經通過驗證後:

 var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, user.Email) }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Email, ClaimTypes.Role); 

     identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", user.Id.ToString())); 
     identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", user.Id.ToString())); 
     identity.AddClaim(new Claim("UserId", user.Id.ToString())); 

     identity.AddClaim(new Claim("ProfileImageUrl", user.ProfileImageUrl)); 
     identity.AddClaim(new Claim("FirstName", user.FirstName)); 
     identity.AddClaim(new Claim("SecondName", user.SecondName)); 

     Int32 unixTimestamp = (Int32)(user.SignUpDate.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; 

     identity.AddClaim(new Claim("SignUpDate", unixTimestamp.ToString())); 

     identity.AddClaim(new Claim("Name", user.FullName)); 
     identity.AddClaim(new Claim("Username", user.Username)); 
     identity.AddClaim(new Claim("Email", user.Email)); 
     identity.AddClaim(new Claim("Role", user.Role)); 
     identity.AddClaim(new Claim("Verified", user.Verified.ToString())); 
     identity.AddClaim(new Claim("VerifiedString", user.Verified ? "Verified" : "Unverified")); 

     if (this.Authentication == null) 
     { 
      return this.View("Login"); 
     } 

     var persist = remember == null ? false : remember.Value; 

     this.Authentication.SignIn(new AuthenticationProperties { IsPersistent = persist }, identity); 

回答

0

如果您在使用權威性的cookie,那麼就是你的問題:Cookie域。你可以爲mysite.co.uk發行另一個cookie。

+0

我添加了什麼正在發生的示例代碼。 –