Hi,
Im using vis studio 2003 and I think wse is out of the question as clients
could be using java which doesnt support it. So I managed to find some code
which allows you to develop a custom soap header called by using a http
module. The problem Im having is I cannot seem to get the event to raise to
fire off my authenticate method in the global.asax. The module is plumbed in
to my web.config file
Code Below:-
TIA
Stu
Public Class Global
Inherits System.Web.Http Application
#Region " Component Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Required by the Component Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r()
End Sub
#End Region
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
End Sub
Sub Session_Start(B yVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
End Sub
Sub Application_Beg inRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_Aut henticateReques t(ByVal sender As Object, ByVal e As
EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Err or(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
End Sub
Sub Session_End(ByV al sender As Object, ByVal e As EventArgs)
' Fires when the session ends
End Sub
Sub Application_End (ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
Sub Authenticate(By Val context As HttpContext, ByVal user As String,
ByVal password As String)
' Web Service authenticate
Dim x As Int16
x = 1
End Sub
End Class
Imports System
Imports System.IO
Imports System.Xml
Imports System.web.Serv ices.Protocols
Public NotInheritable Class WebServiceAuthe ntication
Implements IHttpModule
Public Delegate Sub WebServiceAuthe nticationEventH andler(ByVal sender As
[Object], ByVal e As WebServiceAuthe nticationEvent)
Private _eventHandler As WebServiceAuthe nticationEventH andler = Nothing
Public Event Authenticate As WebServiceAuthe nticationEventH andler
' AddHandler(ByVa l value As WebServiceAuthe nticationEventH andler)
' RemoveHandler(B yVal value As WebServiceAuthe nticationEventH andler)
' _eventHandler = value
' End RemoveHandler
' End RaiseEvent
Public Sub Dispose() Implements System.Web.IHtt pModule.Dispose
RemoveHandler Authenticate, _eventHandler
End Sub 'Dispose
Public Sub Init(ByVal app As HttpApplication ) Implements
System.Web.IHtt pModule.Init
AddHandler app.Authenticat eRequest, AddressOf Me.OnEnter
End Sub 'Init
Private Sub OnAuthenticate( ByVal e As WebServiceAuthe nticationEvent)
If _eventHandler Is Nothing Then
Return
End If
_eventHandler(M e, e)
If Not (e.User Is Nothing) Then
e.Context.User = e.Principal
End If
AddHandler Authenticate, _eventHandler
RaiseEvent Authenticate(Me , e)
End Sub 'OnAuthenticate
Public ReadOnly Property ModuleName() As String
Get
Return "WebServiceAuth entication"
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
' Save the current position of stream.
Dim posStream As Long = HttpStream.Posi tion
' If the request contains an HTTP_SOAPACTION
' header, look at this message.
If context.Request .ServerVariable s("HTTP_SOAPACT ION") 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(HttpSt ream)
' Reset the stream position.
HttpStream.Posi tion = posStream
' Bind to the Authentication header.
soapUser = dom.GetElements ByTagName("User ").Item(0).Inne rText
soapPassword =
dom.GetElements ByTagName("Pass word").Item(0). InnerText
Catch e As Exception
' Reset the position of stream.
HttpStream.Posi tion = posStream
' Throw a SOAP exception.
Dim name As New XmlQualifiedNam e("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 WebServiceAuthe nticationEvent( context, soapUser,
soapPassword))
Return
End Sub 'OnEnter
End Class 'WebServiceAuth enticationModul e
Imports System
Imports System.Web
Imports System.Security .Principal
Public Class WebServiceAuthe nticationEvent
Inherits EventArgs
Private _IPrincipalUser As Iprincipal
Private _Context As HttpContext
Private _User As String
Private _Password As String
Public Sub New(ByVal context As HttpContext)
_Context = context
End Sub 'New
Public Sub New(ByVal context As HttpContext, ByVal user As String, ByVal
password As String)
_Context = context
_User = user
_Password = password
End Sub 'New
Public ReadOnly Property Context() As HttpContext
Get
Return _Context
End Get
End Property
Public Property Principal() As IPrincipal
Get
Return _IPrincipalUser
End Get
Set(ByVal Value As IPrincipal)
_IPrincipalUser = value
End Set
End Property
Public Overloads Sub Authenticate()
Dim i As New GenericIdentity (User)
Me.Principal = New GenericPrincipa l(i, New String(-1) {})
End Sub 'Authenticate
Public Overloads Sub Authenticate(By Val roles() As String)
Dim i As New GenericIdentity (User)
Me.Principal = New GenericPrincipa l(i, roles)
End Sub 'Authenticate
Public Property User() As String
Get
Return _User
End Get
Set(ByVal Value As String)
_User = value
End Set
End Property
Public Property Password() As String
Get
Return _Password
End Get
Set(ByVal Value As String)
_Password = value
End Set
End Property
Public ReadOnly Property HasCredentials( ) As Boolean
Get
If _User Is Nothing OrElse _Password Is Nothing Then
Return False
End If
Return True
End Get
End Property
End Class 'WebServiceAuth enticationEvent 1 6333
WSE should not be out of the question. There are many tools for languages
from java to cobol to consume basic web services. All you client should need
to do is add custom headers to the soap envelope that are based on the spec
of the version of wes that you are using. We are developing web services
that are using a username token over ssl. the clients app will have to
generate the raw headers to add to the soap envelope before sending teh
request
"Stu" wrote: Hi,
Im using vis studio 2003 and I think wse is out of the question as clients could be using java which doesnt support it. So I managed to find some code which allows you to develop a custom soap header called by using a http module. The problem Im having is I cannot seem to get the event to raise to fire off my authenticate method in the global.asax. The module is plumbed in to my web.config file Code Below:-
TIA
Stu
Public Class Global Inherits System.Web.Http Application
#Region " Component Designer Generated Code "
Public Sub New() MyBase.New()
'This call is required by the Component Designer. InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Required by the Component Designer Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent() components = New System.Componen tModel.Containe r() End Sub
#End Region
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started End Sub
Sub Session_Start(B yVal sender As Object, ByVal e As EventArgs) ' Fires when the session is started End Sub
Sub Application_Beg inRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request End Sub
Sub Application_Aut henticateReques t(ByVal sender As Object, ByVal e As EventArgs) ' Fires upon attempting to authenticate the use End Sub
Sub Application_Err or(ByVal sender As Object, ByVal e As EventArgs) ' Fires when an error occurs End Sub
Sub Session_End(ByV al sender As Object, ByVal e As EventArgs) ' Fires when the session ends End Sub
Sub Application_End (ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application ends End Sub
Sub Authenticate(By Val context As HttpContext, ByVal user As String, ByVal password As String) ' Web Service authenticate Dim x As Int16 x = 1 End Sub
End Class
Imports System Imports System.IO Imports System.Xml Imports System.web.Serv ices.Protocols
Public NotInheritable Class WebServiceAuthe ntication Implements IHttpModule
Public Delegate Sub WebServiceAuthe nticationEventH andler(ByVal sender As [Object], ByVal e As WebServiceAuthe nticationEvent)
Private _eventHandler As WebServiceAuthe nticationEventH andler = Nothing
Public Event Authenticate As WebServiceAuthe nticationEventH andler
' AddHandler(ByVa l value As WebServiceAuthe nticationEventH andler)
' RemoveHandler(B yVal value As WebServiceAuthe nticationEventH andler) ' _eventHandler = value ' End RemoveHandler
' End RaiseEvent
Public Sub Dispose() Implements System.Web.IHtt pModule.Dispose RemoveHandler Authenticate, _eventHandler
End Sub 'Dispose
Public Sub Init(ByVal app As HttpApplication ) Implements System.Web.IHtt pModule.Init AddHandler app.Authenticat eRequest, AddressOf Me.OnEnter
End Sub 'Init
Private Sub OnAuthenticate( ByVal e As WebServiceAuthe nticationEvent) If _eventHandler Is Nothing Then Return End If _eventHandler(M e, e) If Not (e.User Is Nothing) Then e.Context.User = e.Principal End If
AddHandler Authenticate, _eventHandler
RaiseEvent Authenticate(Me , e)
End Sub 'OnAuthenticate
Public ReadOnly Property ModuleName() As String Get Return "WebServiceAuth entication" 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
' Save the current position of stream. Dim posStream As Long = HttpStream.Posi tion
' If the request contains an HTTP_SOAPACTION ' header, look at this message. If context.Request .ServerVariable s("HTTP_SOAPACT ION") 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(HttpSt ream)
' Reset the stream position. HttpStream.Posi tion = posStream
' Bind to the Authentication header. soapUser = dom.GetElements ByTagName("User ").Item(0).Inne rText soapPassword = dom.GetElements ByTagName("Pass word").Item(0). InnerText Catch e As Exception ' Reset the position of stream. HttpStream.Posi tion = posStream
' Throw a SOAP exception. Dim name As New XmlQualifiedNam e("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 WebServiceAuthe nticationEvent( context, soapUser, soapPassword)) Return
End Sub 'OnEnter End Class 'WebServiceAuth enticationModul e
Imports System Imports System.Web Imports System.Security .Principal
Public Class WebServiceAuthe nticationEvent Inherits EventArgs Private _IPrincipalUser As Iprincipal Private _Context As HttpContext Private _User As String Private _Password As String
Public Sub New(ByVal context As HttpContext) _Context = context
End Sub 'New
Public Sub New(ByVal context As HttpContext, ByVal user As String, ByVal password As String) _Context = context _User = user _Password = password
End Sub 'New
Public ReadOnly Property Context() As HttpContext Get Return _Context End Get End Property
Public Property Principal() As IPrincipal Get Return _IPrincipalUser End Get Set(ByVal Value As IPrincipal) _IPrincipalUser = value End Set End Property
Public Overloads Sub Authenticate() Dim i As New GenericIdentity (User) Me.Principal = New GenericPrincipa l(i, New String(-1) {})
End Sub 'Authenticate
Public Overloads Sub Authenticate(By Val roles() As String) Dim i As New GenericIdentity (User) Me.Principal = New GenericPrincipa l(i, roles)
End Sub 'Authenticate
Public Property User() As String Get Return _User End Get Set(ByVal Value As String) _User = value End Set End Property
Public Property Password() As String Get Return _Password End Get Set(ByVal Value As String) _Password = value End Set End Property
Public ReadOnly Property HasCredentials( ) As Boolean Get If _User Is Nothing OrElse _Password Is Nothing Then Return False End If Return True End Get End Property End Class 'WebServiceAuth enticationEvent
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JP |
last post by:
I need to be able to trap errors at the application level. I added this code
to the Global.asax file. The code I wrote is supposed to get the last error
that was generated and write to the event log as well as fire up my email
class and generate an email to send me the error. But no matter what I do, I
still get the icky looking yellow and white error screens.
I’ve turned on customErrors in the web.config but not default URL setting....
|
by: Arjen |
last post by:
Hi,
I load my website settings inside the global.asax file. For this I have to
use the context, to get the roles from the current browsing client.
The problem is that there is no context at that time. (no reference) When I
add these code
lines (from global.asax) inside an aspx file, then it works. Because there
is a context.
|
by: Joe Reazor |
last post by:
I understand how Web.Config inheritance works between a parent application
and sub applications under the parent. But what I was wondering was if
there was a similar way to do the same thing for the Global.asax class?
Reason being, I am setting up user authentication and authorization. I have
coded up my Application_AuthenticateRequest method in the Global.asax file
to create an identity and principal which are attached to the Context...
|
by: bcharles |
last post by:
My company has an existing web app. It was written by someone who has left.
It generates an error if authentication fails and sends an email to the email
address of the person who left. I want it to send the email to me. I have
found Global.asax and Global.asax.cs in the virtual directory. The
Global.asax says Application CodeBehind and points to Gloabl.asax.cs
The Global.asax.cs has a Application_Error method and I changed the email...
|
by: randyr |
last post by:
I am developing an asp.net app based on a previous asp application.
in the asp applications global.asa file I had several
<object id="id" runat="server" scope="scope" class="comclass"> tags for
objects that the app used to speed up some global level data access and
functionality.
I have recoded the class libraries in .net and would like to acomplish the
same functionality in asp.net.
| |
by: John Holgerson |
last post by:
Hi, is it possible to get informations about the exception that
occured in that method??
(global.asax)
protected void Application_Error(Object sender, System.EventArgs e) {
}
thanks for help
John
|
by: |
last post by:
Hi all,
Is it possible to have custom function/subroutines in global.asax? e.g.
DoMyWork(i as integer) etc etc. If yes, how can I access this code in my
..aspx pages? I know I can put this into a seperate dll in the bin directory,
but to keep it simple global.asax would be nice too..
TIA!
|
by: Jonas |
last post by:
Hi!
I have an Application_Error method in global.asax that uses Server.Transfer
to move execution to a custom error page. This works fine when an exception
is thrown in one of the aspx or ascx files. The errorpage.aspx uses
Server.GetLastError() and shows a friendly error page.
But when it happens in global.asax itself, the Server.Transfer does not
work. Do I have to use some kind of special exception handling for exception
in...
|
by: tshad |
last post by:
I am setting up Authentication that I want to put in multiple Web Sites on
my server.
I found a good article on this and am looking at moving my code from my
Global.asax file to an HTTP Module. This works fine.
But I was curious about what would happen if I left the Global.asax code in
(which is identical to the HTTPModule code) as well as added the HTTPModule.
Both call the same event and both sets of code is executed.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |