本文介绍了带有Cookie的自定义身份. Cookie不能胜任的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我创建了自定义标识和主体类.
在以下代码中使用了代码: http://www.asp.net/security /tutorials/forms-authentication-configuration-and-advanced-topics-vb [ ^ ]

我在这两行中添加了持久性cookie:

Hello,

I''ve created a Custom Identity and Principal Classes.
Used the code in: http://www.asp.net/security/tutorials/forms-authentication-configuration-and-advanced-topics-vb[^]

I added persistent cookie in this two line:

// Create the cookie that contains the forms authentication ticket
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(txtEmail.Text, chkRemeberMe.Checked);

// Determine redirect URL and send user there
string redirUrl = FormsAuthentication.GetRedirectUrl(txtEmail.Text, chkRemeberMe.Checked);



自定义标识效果很好,但 cookie 却不能.
关闭浏览器时,它注销了我.

有什么想法吗?:confused :: confused :: confused:

谢谢,
BguyB



The Custom Identity works great, but NOT the cookie.
It logs me out when closing the browser.

Any thoughts?:confused::confused::confused:

Thanks,
BguyB

推荐答案


if (chkRemeberMe.Checked)
{
    authCookie.Expires = authCookie.Expires.AddYears(50);
    expiration = ticket.Expiration.AddYears(50);
}
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, expiration, ticket.IsPersistent, userDataString);




到目前为止,它使我无法登录.

谢谢,
盖伊




So far it keeps me loged in.

Thanks,
Guy


这篇关于带有Cookie的自定义身份. Cookie不能胜任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:50