如何通过浏览器维护会话,直到它关闭任何登录表单 [英] how to maintain a session through out a browser until it closes with out any login form

查看:80
本文介绍了如何通过浏览器维护会话,直到它关闭任何登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过浏览器维护会话,直到它以任何登录表单关闭

how to maintain a session through out a browser until it closes with out any login form

推荐答案

尝试使用GUID概念



Guid obj = new Guid();

session [unqno] = obj.ToString();





在HomePage加载中使用
Try with GUID Concept

Guid obj= new Guid();
session["unqno"]=obj.ToString();


Use this in HomePage load


在我的视图中,如果您只是想避免会话超时的身份验证,您可以选择在应用程序上下文中成功维护SessionID认证。



第1步:

成功验证后,将当前的SessionID和UserId保持在应用程序状态。

另外将UserID保留在当前会话中。



第2步:

页面加载

如果存在UserID当前会话然后继续。

否则检查请求会话ID(您可以从HttpContext.Current.Request.Cookies [ASP.NET_SessionId]。值确定)是否存在于您的应用程序状态中。 />
{

如果存在,则将UserID存储在当前会话中并继续。

其他用户第一次点击,因此重定向到登录页面。 />
}



第3步:

使用以下事件的用户会话到期;

1.用户退出

2.从JavaScript抓取浏览器关闭事件并通知服务器关闭会话。



其他指向注意:

1.你必须明白,你不应该使用会话变量这种情况。

2.使用以下配置以避免再次生成相同的SessionId,并避免与其他用户会话冲突。

< configuration>

< system.web>

regenerateExpiredSessionId =false/>





3.仍有可能在您的应用程序状态中有一些实时的SessionID,当浏览器崩溃或发生异常时实际上不存在。所以需要定期清理它们。
In my view if you just want to avoid authentication on session timeout you can opt for maintaining SessionID in Application Context once successfully authenticated.

STEP 1:
After successful authentication keep the current SessionID and UserId in the Application State.
Also keep the UserID in the current session.

STEP 2:
On page load
If UserID exists in current session then go ahead.
Else check if the Request SessionID(you could determine from HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value) exists in your Application State.
{
If exists then store the UserID in current session and go ahead.
Else user hits first time, so redirect to logon page.
}

STEP 3:
Expire the user session on following events;
1. Logout by user
2. Catch the browser close event from JavaScript and notify the server to close the session.

Other points to note:
1. You must understand that, you should not use the session variable in this scenario.
2. Use following configuration to avoid generate same SessionId again, and avoid conflicting with other user session.
<configuration>
<system.web>
regenerateExpiredSessionId="false" />


3. Still there could be some live SessionID in your Application state, which actually does not exists as browser crashed or something unusual happened. So need to clean those periodically.


这篇关于如何通过浏览器维护会话,直到它关闭任何登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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