自动将会话超时和重定向页面检测到asp.net中的登录页面 [英] detetcting a session timeout and redirct page automatically to login page in asp.net

查看:75
本文介绍了自动将会话超时和重定向页面检测到asp.net中的登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


自动检测会话超时和重定向页面以登录到asp.net中的登录页面.
如果用户在任何页面上...

怎么做...

我已经搜索了所有内容


在此先感谢

解决方案

首先,您需要处理 Session_Start& Global.asax 中的Session_End .在Session中有一个变量,如下所示.抱歉,代码在VB中,您可以轻松地将其转换为C#.

  Sub  Session_Start( ByVal 发​​件人 As  对象 ByVal  e  As  EventArgs)
    ' 启动新会话时运行的代码
    会话(" )= 错误
结束 

 Session_End( ByVal 发​​件人 As  对象 ByVal  e  As  EventArgs)
    ' 在会话结束时运行的代码.
    ' 注意:仅在会话状态模式下才会引发Session_End事件
    在Web.config文件中,将' 设置为InProc.如果会话模式设置为StateServer 
    ' 或SQLServer,不会引发该事件.
    会话(" )= 错误
结束 



然后,编写代码以在执行任何操作时检查 Session("UserLogged").根据该值,重定向到登录"页面.


您好,

实现表单身份验证,它将做所有事情.

以下链接可帮助您实施表单身份验证.

http://support.microsoft.com/kb/301240 [ http://www.codedigest.com/Articles/ASPNET/112_Implementing_Forms_Authentication_in_ASPNet_20.aspx [ ^ ]

但是,如果您的用户是匿名用户,则应该进行身份认证或在global.asax页面中使用Session_Start和Session_End事件.


hi
detetcting a session timeout and redirct page automatically to login page in asp.net..
if user on any page...

how to do it...

i have search everything


thanks in advance

解决方案

First you need to handle Session_Start & Session_End in Global.asax. Have a variable in Session like below. Sorry the code was in VB, you can easily convert this into C#.

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when a new session is started
    Session("UserLogged") = False
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when a session ends.
    ' Note: The Session_End event is raised only when the sessionstate mode
    ' is set to InProc in the Web.config file. If session mode is set to StateServer
    ' or SQLServer, the event is not raised.
    Session("UserLogged") = False
End Sub



Then write your code to check Session("UserLogged") whenever an action is performed. Based on the value, redirect to Login page.


Hi,

Implement form authentication and it will do all the thing.

The below link help you to implement form authentication.

http://support.microsoft.com/kb/301240[^]

http://www.codedigest.com/Articles/ASPNET/112_Implementing_Forms_Authentication_in_ASPNet_20.aspx[^]

But if your user are anonymous then you should go for coustom authentication or use Session_Start and Session_End event avail in global.asax page.


这篇关于自动将会话超时和重定向页面检测到asp.net中的登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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