📄 webserviceauthenticationmodule.vb
字号:
Imports System
Imports System.Web
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Text
Imports System.Web.Services.Protocols
Namespace Microsoft.WebServices.Security
Public NotInheritable Class WebServiceAuthenticationModule
Implements IHttpModule
Private _eventHandler As WebServiceAuthenticationEventHandler = Nothing
Public Event Authenticate As WebServiceAuthenticationEventHandler
Add
AddHandler _eventHandler, AddressOf value
End Add
Remove
RemoveHandler _eventHandler, AddressOf value
End Remove
End Event
Public Overrides Overloads Sub Dispose() Implements IHttpModule.Dispose
End Sub
Public Sub Overrides Overloads Init(app As HttpApplication) Implements IHttpModule.Init
AddHandler app.AuthenticateRequest, New EventHandler(AddressOf Me.OnEnter)
End Sub
Private Sub OnAuthenticate(ByVal e As WebServiceAuthenticationEvent)
If (_eventHandler Is Nothing) Then
Return
End If
_eventHandler(Me, e)
If Not (e.User Is Nothing) Then
e.Context.User = e.Principal
End If
End Sub
Public ReadOnly Property ModuleName() As String
Get
Return "WebServiceAuthentication"
End Get
End Property
Sub OnEnter(ByVal source As Object, ByVal eventArgs As EventArgs)
Dim app As HttpApplication = CType(source, HttpApplication)
Dim context As HttpContext = app.Context
Dim HttpStream As Stream = context.Request.InputStream
' Current position of stream
Dim posStream As Long = HttpStream.Position
' If the request contains an HTTP_SOAPACTION
' header we'll look at this message
If (context.Request.ServerVariables("HTTP_SOAPACTION") Is Nothing) Then
Return
End If
' Load the body of the HTTP message
' into an XML document
Dim dom As New XmlDocument()
Dim soapUser As String
Dim soapPassword As String
Try
dom.Load(HttpStream)
' Reset the stream position
HttpStream.Position = posStream
' Bind to the Authentication header
soapUser = dom.GetElementsByTagName("User").Item(0).InnerText
soapPassword = dom.GetElementsByTagName("Password").Item(0).InnerText
Catch e As Exception
' Reset Position of stream
HttpStream.Position = posStream
' Throw a SOAP Exception
Dim name As New XmlQualifiedName("Load")
Dim soapException As New SoapException("Unable to read SOAP request", name, e)
Throw soapException
End Try
' Raise the custom global.asax event
OnAuthenticate(New WebServiceAuthenticationEvent(context, soapUser, soapPassword))
Return
End Sub
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -