asp.net 启用httpmoule 设置访问权限 vb.net

web.config 文件注册模块,注意websever节点和其中的modules节点只能有一个否则会报错

<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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值