473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

HTTPModules vs Global.asax

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.

It seems to do the HTTPModule first and then does the Global.asax code.

I am going to take the Global.asax code out, but am curious as to what the
order is that these things are called. Why is the HTTPModule called first
and then the Global.asax?

Here is the code from the HttpModule:
***********************************************
namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest) );
}

private void Application_AuthenticateRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
************************************************** ***********

Thanks,

Tom

May 3 '06 #1
2 4201
You use the HTTPModule want to intercept the call before it gets to your
application.???!!
That is why the HTTPModule is executed first.

SA
"tshad" <ts**********@ftsolutions.com> wrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
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.

It seems to do the HTTPModule first and then does the Global.asax code.

I am going to take the Global.asax code out, but am curious as to what the
order is that these things are called. Why is the HTTPModule called first
and then the Global.asax?

Here is the code from the HttpModule:
***********************************************
namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest) );
}

private void Application_AuthenticateRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
************************************************** ***********

Thanks,

Tom

May 3 '06 #2
I use HttpModules because they are far more reusable. For example, I have
an Fuel.Web.ErrorModule.

which hooks into application.Error and does some error logging (via
log4net). I've reused the module across countless applications.

Similarly, I have a Fuel.Web.LocalizationModule which is at the core of the
localization stuff i use
(http://openmymind.net/index.aspx?doc...=4#urlrewrite). Again, all
because they are highly reusable.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"MSDN" <sq**********@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP04.phx.gbl...
You use the HTTPModule want to intercept the call before it gets to your
application.???!!
That is why the HTTPModule is executed first.

SA
"tshad" <ts**********@ftsolutions.com> wrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
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.

It seems to do the HTTPModule first and then does the Global.asax code.

I am going to take the Global.asax code out, but am curious as to what
the
order is that these things are called. Why is the HTTPModule called
first
and then the Global.asax?

Here is the code from the HttpModule:
***********************************************
namespace AuthModule
{
public class SetIdentity: IHttpModule
{
public SetIdentity()
{
}

public void Init(HttpApplication context)
{
context.AuthenticateRequest +=
(new EventHandler(this.Application_AuthenticateRequest) );
}

private void Application_AuthenticateRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if(authCookie==null)
return;

// Get the authentication ticket
// and rebuild the principal & identity
FormsAuthenticationTicket authTicket =
FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char [] {'|'});
GenericIdentity userIdentity = new GenericIdentity(authTicket.Name);
GenericPrincipal userPrincipal =
new GenericPrincipal(userIdentity, roles);
context.User = userPrincipal;
}

public void Dispose()
{
}
}
}
************************************************** ***********

Thanks,

Tom


May 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ian Turner | last post by:
Hi, Is there anyway, without dropping back to C++ and ISAPI filters, whereby I can route requests to virtual url paths through to the ASPNET runtime and ultimately processed by an HttpModule? ...
2
by: Aurel | last post by:
Hi, I have create a httpmodule but I have some problems. I can't access to the session. Even if I create my class like this public class myModule: IHttpModule, IRequiresSessionState {} ...
3
by: msnews.microsoft.com | last post by:
Hi... I'm learning about HTTPModules, so please allow me a beginner's question. I read that "you gain low-level access to the HTTPRequests and responses processed by the ASP.NET framework"....
1
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are...
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
0
by: GoogleNewsReaderMan | last post by:
In 1.1 I could handle events in global.asax simply by having a method named <ModuleName>_<EventName>(...) and when the HttpModule raised the event, it would get handled in global.asax automatically...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
1
by: Samuel R. Neff | last post by:
We have a problem with Web.config inheritance in two of our applications. We have an old app which is poorly written and must be in the root of the server. We have a newer app which runs from a...
2
by: DamienS | last post by:
Hi, I'm trying to get away from using global.asax for reasons of 'neatness'. Am I able to register a HTTPModule that captures the starting of a user session? Isn't Session_Start an event in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.