Imports Microsoft.VisualBasic
Imports System.Web.UI.Page
Imports System.Data.OleDb
Imports System.Data
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Public Class roots
Inherits System.Web.UI.Page
Protected Overrides Sub OnInit(e As EventArgs)
If Session("username") = "" Then
Response.Redirect("~/login.aspx")
Else
MyBase.OnInit(e)
End If
End Sub
End Class需要判定的页面直接添加以下代码Inherits roots类 用户登录 判定session为空
Imports System.Web.UI.Page
Imports System.Data.OleDb
Imports System.Data
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Public Class roots
Inherits System.Web.UI.Page
Protected Overrides Sub OnInit(e As EventArgs)
If Session("username") = "" Then
Response.Redirect("~/login.aspx")
Else
MyBase.OnInit(e)
End If
End Sub
End Class需要判定的页面直接添加以下代码Inherits roots类 用户登录 判定session为空
解决方案 »
- js 跨域访问 iframe 拒绝访问???
- 数据库问题,急!
- MVC不用.NET ENTITY FRAMEWORK可以吗?直接用ADO.NET
- 存储过程编译错误
- page 和 this 的区别
- 怎么从程序里改变FormView里面按钮的CommandName?
- 小弟也想和大侠换c#程序学习
- ASP.NET中有没有可以手工输入文字的DROPDOWNLIST控件(类似VB中的ComboBox)?还有下拉菜单中文字超长部分有没有办法显示??
- 这段代码是啥意思啊,看了半天,没有看明白,各为老大..
- ASP代码的自动生成系统
- 一个狗血让我心焦的问题。IE9中出现的神奇BUG
- IIS假死,重启IIS恢复,阶段性出现
那么我就给多一个方向好以后继续修炼
AOP 面向切面编程
Namespace mynamespace
Public Class myhandler
Implements IHttpModule Public Sub Init(application As HttpApplication) Implements IHttpModule.Init
AddHandler application.AcquireRequestState, AddressOf application_AcquireRequestState
End Sub Public Sub application_AcquireRequestState(sender As Object, e As EventArgs)
Dim app As HttpApplication = sender
If app.Context.Session("username").ToString.Trim() = "" Then
app.Context.Response.Redirect("~/login.aspx")
End If
End Sub Public Sub dispose() Implements System.Web.IHttpModule.Dispose
End Sub
End Class
End Namespace这是我使用ihttpmodule的方法,但始终无法实现上述功能,web.config也进行了添加(iis7):<modules>
<add type="mynamespace" name="myhandler" />
</modules>
大伙看看问题出在哪里?继续修炼,共同提高嘛!
Imports Microsoft.VisualBasic
Imports System.Web
Namespace Samples.AspNet.VB Public Class SessionModule
Implements IHttpModule
Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init
AddHandler context.AcquireRequestState, AddressOf Me.context_AcquireRequestState
End Sub Private Sub context_AcquireRequestState(sender As Object, e As EventArgs)
Dim app As HttpApplication = CType(sender, HttpApplication)
Dim requestUrl As String = app.Context.Request.Path
Dim filename As String = System.IO.Path.GetFileName(requestUrl)
If app.Context.Session Is Nothing Then
Return
End If
If app.Context.Session("username") = "" Then
If filename <> "login.aspx" Then
app.Context.Server.Transfer("~/login.aspx") '不清楚为什么无法使用 app.Context.Response.Redirect("~/login.aspx")进行跳转?
End If
End If
End Sub
Public Sub Dispose() Implements IHttpModule.Dispose
End Sub
End Class
End Namespace