带有Cookie的自定义身份. Cookie不能胜任 [英] Custom Identity with cookie. cookie don't do the job

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

问题描述

你好,

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

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

推荐答案

在cookie上设置到期日期.如果不这样做,它将在浏览器退出时失效.
Set an expiration date on the cookie. If you don''t, it expires when the browser exits.


我这样做了,但是可能不在正确的位置.

我现在使用:
I did, but maybe not in the right place.

I now use:
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不能胜任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆