我正在尝试加密一些 userData 以使用 Forms 身份验证创建我自己的自定义 IPrincipal 和 IIdentity 对象 - 我已将代表我登录用户的对象序列化为 Json 并创建了我的 FormsAuthentication 票证,如下所示:
string user_item = GetJsonOfLoggedinUser();/*get JSON representation of my logged in user*/
System.Web.Security.FormsAuthenticationTicket ticket =
new System.Web.Security.FormsAuthenticationTicket(1,
WAM.Utilities.SessionHelper.LoggedInEmployee.F_NAME + " "
+ WAM.Utilities.SessionHelper.LoggedInEmployee.L_NAME,
DateTime.Now, DateTime.Now.AddMinutes(30), false, user_item);
string encrypted_ticket = System.Web.Security.FormsAuthentication.Encrypt(ticket);
HttpCookie auth_cookie =
new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, encrypted_ticket);
Response.Cookies.Add(auth_cookie);
然而,字符串encrypted_ticket
总是null
。长度有限制吗user_item
string?
谢谢
穆斯塔法
作为这个问题的补充,当userData参数是null
the 加密票也将是null
.
在这个例子中:
var ticket = new System.Web.Security.FormsAuthenticationTicket(1,
"username",
DateTime.Now, DateTime.Now.AddMinutes(30), false, null);
string encrypted_ticket = System.Web.Security.FormsAuthentication.Encrypt(ticket);
加密票现在产量null
。但是,当使用空字符串或string.Empty
为了userData我们得到一个有效的参数加密票.
这也有一些记录MSDN http://msdn.microsoft.com/en-us/library/kybcs83h.aspx
Note
userData 参数不能为空。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)