Global.asax Inheritance?

J

Joe Reazor

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 User.
I have done this at my root web level. Under the root web, I then have
other sub applications in sub folders that are also protected by the same
authentication and authorization. I was hoping that I would not have to add
and maintain the same code in the global.asax files for each of these sub
apps in order to have access to the principal and identity objects set at
the parent level. Any thoughts?


TIA.
==============
Joe Reazor
Gorbel Inc.
email: joereaATgorbelDOTcom
 
J

John Saunders

Global.asax generates a class called "global". I believe you can create a
base class called "GlobalBase" and inherit all of your global.asax's from
that.
 
S

Steven Cheng[MSFT]

Hi Jeo,

As for the sharing a certain Global class among multi web applications, I
think John's suggestion that making a base
Global class derived fron the System.Web.HttpApplication class and put
those common authorization code in it. Then, in all those web applications,
derived their Global class from this Base Global class.

Also, beside using a base Global class, we can use the asp.net's HttpModule
to handle those application level events such as:
Application_Start
Application_BeginRequest
Application_AuthenticateRequest

Thus, we can use a certain HttpModule in multi web applications, only need
to register it in the web.config.
Here are some referencein MSDN on using HttpModule:

#Custom HttpModule Example
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomhttpmodules.
asp?frame=true

http://cephas.net/blog/2003/09/25/aspnet_httpmodule_security_example.html

Custom Authentication provider by implementing IHttpModule, IPrincipal and
IIdentity

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
J

Joe Reazor

Steven,
Thanks for the help. This should be useful. I'll post if I have any
other questions.


==============
Joe Reazor
Gorbel Inc.
email: joereaATgorbelDOTcom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top