如何利用ASP.NET 2.0高效应对会话超时问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计284个文字,预计阅读时间需要2分钟。
在构建的网站中,我们需确保在会话结束时将用户重定向到默认页面。不使用繁琐的代码,以下为简洁实现:
使用Session_End事件和Response.Redirect方法实现重定向:
vbSub Session_End(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect(default.aspx)End Sub
在我们正在建设的网站上.我们需要能够在会话结束时将用户重定向到默认页面.乍一看,我们使用Session_End和Response.Redirect来完成这项工作.
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect("~/global/exit.aspx") End Sub
但是它会在此上下文错误中生成一个无法响应的垃圾邮件.当然,我们不想垃圾邮件我们的服务器错误日志.
使用ASP.NET 2.0处理会话结束的最有效方法是什么?
我们将以下代码添加到global.asax.cs文件中:private void IsAuthenticated() { string vFileName = Path.GetFileName(HttpContext.Current.Request.Path); string vExt = Path.GetExtension(vFileName).ToLower(); if ((vFileName != "Login.aspx") && (vExt == ".aspx")) { if (HttpContext.Current.Session["LoggedIn"] == null) { HttpContext.Current.Response.Redirect("~/Login.aspx"); } } } void Application_PostAcquireRequestState(object sender, EventArgs e) { IsAuthenticated(); }
NS:我们的Global .asax文件中的第一行是:
<%@ Application Inherits="???.Global" Language="C#" %>
本文共计284个文字,预计阅读时间需要2分钟。
在构建的网站中,我们需确保在会话结束时将用户重定向到默认页面。不使用繁琐的代码,以下为简洁实现:
使用Session_End事件和Response.Redirect方法实现重定向:
vbSub Session_End(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect(default.aspx)End Sub
在我们正在建设的网站上.我们需要能够在会话结束时将用户重定向到默认页面.乍一看,我们使用Session_End和Response.Redirect来完成这项工作.
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect("~/global/exit.aspx") End Sub
但是它会在此上下文错误中生成一个无法响应的垃圾邮件.当然,我们不想垃圾邮件我们的服务器错误日志.
使用ASP.NET 2.0处理会话结束的最有效方法是什么?
我们将以下代码添加到global.asax.cs文件中:private void IsAuthenticated() { string vFileName = Path.GetFileName(HttpContext.Current.Request.Path); string vExt = Path.GetExtension(vFileName).ToLower(); if ((vFileName != "Login.aspx") && (vExt == ".aspx")) { if (HttpContext.Current.Session["LoggedIn"] == null) { HttpContext.Current.Response.Redirect("~/Login.aspx"); } } } void Application_PostAcquireRequestState(object sender, EventArgs e) { IsAuthenticated(); }
NS:我们的Global .asax文件中的第一行是:
<%@ Application Inherits="???.Global" Language="C#" %>

