当会话未在 asp.net 处理程序中填写时,如何重定向页面?
问问题
323 次
1 回答
0
将以下类添加到 app_code(站点根目录)
Imports Microsoft.VisualBasic
Public Class SecurityCrm
Implements IHttpModule
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.BeginRequest, AddressOf FirstTest
End Sub
Private Sub FirstTest(ByVal sender As Object, ByVal e As EventArgs)
Dim app As HttpApplication
app = CType(sender, HttpApplication)
Dim cookie As HttpCookie ' Replace with Session Object
cookie = app.Request.Cookies("username") ' Replace with your Session
If cookie Is Nothing Then
app.Response.redirect("/Cms/LoginSystem/login.asp?u=" & app.Request.Url.AbsolutePath)
app.Response.end()
Else
'app.Response.write("Cookie: " & cookie.value)
End If
End Sub
结束类
然后在 web.config 中注册它。
<httpModules>
<add type="SecurityCrm" name="SecurityCrm.app_code" />
</httpModules>
于 2012-09-14T06:54:56.423 回答