开发者

FormsAuthenticationTicket.Version returns invalid version number

Is there any limit开发者_开发百科 on the size/numbers in the version number of the FormsAuthenticationTicket.

I tried to create an ASP.NET cookie using forms authentication, with a large version number(ex: 1234567 need this number for identification purposes). But when I decrypt the cookie I get 135 as the version number.

Initially the old forms authentication cookie was removed, in order to add new information.

Response.Cookies.Remove(FormsAuthentication.FormsCookieName);

Following is the code I used to create the FormsAuthentication cookie.

FormsAuthenticationTicket newAuthTicket = new FormsAuthenticationTicket(1234567, un, DateTime.Now, DateTime.Now.AddHours(5F), false, user_data);
HttpCookie newauthCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(newAuthTicket));

Response.Cookies.Add(newauthCookie);

After retrieving the cookie, the version number I got was 135. This number varies with different version numbers.

string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];

if (authCookie == null)
{
    return;
}

FormsAuthenticationTicket authTkt = null;
authTkt = FormsAuthentication.Decrypt(authCookie.Value);

if (authTkt == null)
{
    return;
}
int versionID = authTkt.Version;

Can someone let me know if it's a bad idea to use such big version numbers, or am I missing something in this.

Thanks for your help, Vijay


make sure that the ticket name is not passed as null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜