.NET会话 - 坚持会话,甚至当用户关闭浏览器 [英] .NET Session - Persist session, even when the user closes the browser

查看:142
本文介绍了.NET会话 - 坚持会话,甚至当用户关闭浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的.NET Framework 3.5和C#。

We use .net framework 3.5 and C#.

我们有一个网站,要求用户登录,所以我们使用一个数据库来检查登录/密码是正确的。

We have a site that requires the user to log in. So we use a database to check if the login / password is correct.

然后我们打个电话为 FormsAuthentication.SetAuthCookie(),所以用户we''l在我的应用程序被记录下来。

Then we make a call to FormsAuthentication.SetAuthCookie() , so the user we´´l be logged in my app.

和所有后续页面中,我们检查是 User.Identity.IsAuthenticated()如果用户登录。

And on all subsequent pages, we check with User.Identity.IsAuthenticated() if the user is logged in.

我们要preserve本次会议,即使在用户关闭borwser。

We want to preserve this session, even when the user closes the borwser.

如何最好的方式做到这一点?

How the best way to do this ?

我们也有失去的会出现问题,突然用户失去了他的认证状态,我认为这与一种新的坚持,我们也可以解决这个问题。

We also have a problem with lost sessions, suddenly the user lost his authenticated status, I think that with that kind of new persist we can also solve that problem.

(对不起,我的英语.....葡萄牙扬声器)

(sorry for my english..... portuguese speaker)

推荐答案

您应该不能混合而言,记住,你在asp.net两个身份验证cookie和会话状态。

You shouldn't mix terms, remember that you have both authentication cookie and session state in asp.net.

您似乎在寻找一个持久的身份验证cookie中。有一个持续的身份验证cookie的尝试

You appear to be looking for a persistent auth cookie. to have a persistent auth cookie try

FormsAuthentication.SetAuthCookie("xxx",true); 

<一个href="http://msdn.microsoft.com/en-us/library/twk5762b(v=vs.90).aspx">http://msdn.microsoft.com/en-us/library/twk5762b(v=vs.90).aspx

传递true将允许身份验证cookie生存的浏览器重新启动。 你也应该考虑在你的web.config表单认证和会话的超时值

passing true will allow the authentication cookie to survive browser restarts. also you should consider your timeout values for forms authentication and session in your web.config

<authentication mode="Forms">
        <!-- The name, protection, and path attributes must match 
       exactly in each Web.config file. -->
        <forms loginUrl="Default.aspx" name=".ASPXFORMSAUTH" protection="All" path="/" timeout="360"/>
    </authentication>

<sessionState mode="InProc" timeout="360" />

这篇关于.NET会话 - 坚持会话,甚至当用户关闭浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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