在我的项目中,需要使用自定义对象代替 FormAuthenticationTicket。我们创建了一个与 FormAuthenticationTicket 具有相同属性的自定义对象。现在我们正在使用我们自己的加密方法来加密这个自定义对象。我们已经成功创建了 FormAuthentication cookie。但是,当我们检查 context.User.Identity.IsAuthenticated 属性时,它始终为 false。这是代码。
CookieData cookieData = new CookieData();
cookieData.ExpirationDate = DateTime.Now.AddMinutes(CookieConstants.DefaultFormsAuthTicketTimeout);
cookieData.LoginToken = LoginToken;
cookieData.Impersonate = (IsImpersonate ? true : false);
cookieData.IsPersistent = IsPersistent;
cookieData.UserData = "<<UserRelated Information>>";
JavaScriptSerializer js = new JavaScriptSerializer();
string strCookieData = js.Serialize(cookieData);
string encryptedTicket = AESEncryption.Encrpyt(strCookieData);
HttpCookie httpCookie = null;
httpCookie = new HttpCookie(cebCookie.Name, encryptedTicket);
if (cebCookie.IsPersistent)
{
httpCookie.Expires = cebCookie.Expires;
}
if (!string.IsNullOrEmpty(cebCookie.Url))
{
httpCookie.Secure = cebCookie.RequireSSL;
httpCookie.Domain = cebCookie.Domain;
}
httpCookie.Path = FormsAuthentication.FormsCookiePath;
HttpContext.Current.Response.Cookies.Set(httpCookie);
我知道这是有线要求。请帮忙。