<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="MyHttpModule" type="TUZHIWEBSITE.MyHttpModule" />
</modules>
</system.webServer>
新建一个后缀.vb的类
Imports System.Web
Public Class MyHttpModule
Implements IHttpModule
Private WithEvents _context As HttpApplication
''' <summary>
''' 您将需要在网站的 Web.config 文件中配置此模块
''' 并向 IIS 注册它,然后才能使用它。有关详细信息,
''' 请参阅以下链接: https://go.microsoft.com/?linkid=8101007
''' </summary>
#Region "IHttpModule 成员"
Public Sub Dispose() Implements IHttpModule.Dispose
' 此处放置清除代码
End Sub
Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init
AddHandler context.BeginRequest, AddressOf OnBeginRequest
End Sub
Public Sub OnBeginRequest(ByVal s As Object, ByVal e As EventArgs)
'Session判断
Dim wy_aplication As New HttpApplication
wy_aplication = s
'wy_aplication.Context.Response.Redirect("~/source/logo.jpg")
Dim path As String = s.Context.Request.Url.ToString() ';//获得请求的url路径
Dim ifimage As Integer = path.IndexOf("source/")
wy_aplication.Context.Response.Write("<h1>Request:" & path & "<hr>")
If Not ifimage Then
wy_aplication.Context.Response.Redirect("https://www.baidu.com")
End If
'Dim n As Integer = path.IndexOf("Login.aspx") ' //判断是否是登陆页面
'If wy_aplication.Context.Session("userinfo") Is Nothing Then
' If n < 0 Then
' wy_aplication.Context.Response.Redirect("~/Login.aspx")
' End If
'Else '已登录,欢迎!
' wy_aplication.Context.Response.Output.Write(wy_aplication.Context.Session("userinfo").ToString + ",WelCome !")
'End If
'' Cookie判断
'Dim UserCookie As HttpCookie = wy_aplication.Context.Request.Cookies("userinfo")
'If UserCookie Is Nothing Then
' If n < 0 Then
' wy_aplication.Context.Response.Redirect("~/Login.aspx")
' End If
'Else '已登录,欢迎!
' If UserCookie.Value <> "" Then
' wy_aplication.Context.Response.Output.Write(UserCookie.Value + ",WelCome !")
' Else
' If n < 0 Then
' wy_aplication.Context.Response.Redirect("~/Login.aspx")
' End If
' End If
'End If
End Sub
#End Region
Public Sub OnLogRequest(ByVal source As Object, ByVal e As EventArgs) Handles _context.LogRequest
' 处理 LogRequest 事件以便为其提供自定义日志记录
' 实现
End Sub
End Class转载请注明出处:
未经允许不得转载:lxfamn » asp.net 启用httpmoule 设置访问权限 vb.net