473,395 Members | 1,535 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,395 software developers and data experts.

IHttpModule Question (storing state)

I've created a custom IHttpModule that does custom authentication.
Currently it stores authenticated user info in a hashtable within the
class so I don't have to re-authenticate against a database everytime a
logged in user hits a page.

So far, it works great.

Here is my question, is my approach for storing logged in users
correct? Meaning, can I be sure that only one instance of my
IHttpModule will be created for my Application. So far, in testing,
this seems to be the case, but I have yet to do any hardcore multiuser
testing. If more than one instance is created, my method of storing
logged in users will fail because each instance will have its own
hashtable.

So if that is the case, I figure I'll make the hashtable static. Does
anyone see any downside to this?
Thanks for your help

Nov 19 '05 #1
4 1832
There will be many instances of your HttpModule withint the application.
ASP.NET creates and maintains a pool of HttpApplication/HttpModules tuples
for servicing requests when the arrives in ASP.NET. So any one instance of
your HttpModule will be thread safe, but shared data won't be. Also, if you
want to cache/share data among them then static variables are an option,
but so is the ASP.NET data Cache. The first part of this article talks about
threading and the app/modules pooled in the HttpPipeline:

http://msdn.microsoft.com/msdnmag/is...g/default.aspx

-Brock
DevelopMentor
http://staff.develop.com/ballen
I've created a custom IHttpModule that does custom authentication.
Currently it stores authenticated user info in a hashtable within the
class so I don't have to re-authenticate against a database everytime
a logged in user hits a page.

So far, it works great.

Here is my question, is my approach for storing logged in users
correct? Meaning, can I be sure that only one instance of my
IHttpModule will be created for my Application. So far, in testing,
this seems to be the case, but I have yet to do any hardcore multiuser
testing. If more than one instance is created, my method of storing
logged in users will fail because each instance will have its own
hashtable.

So if that is the case, I figure I'll make the hashtable static. Does
anyone see any downside to this?

Thanks for your help


Nov 19 '05 #2
Hello Mike,

I think you do have to make it static. I believe that if you put a ctor on
your on your HttpModule, you'll see that its recreated.

--
Matt Berther
http://www.mattberther.com
I've created a custom IHttpModule that does custom authentication.
Currently it stores authenticated user info in a hashtable within the
class so I don't have to re-authenticate against a database everytime
a logged in user hits a page.

So far, it works great.

Here is my question, is my approach for storing logged in users
correct? Meaning, can I be sure that only one instance of my
IHttpModule will be created for my Application. So far, in testing,
this seems to be the case, but I have yet to do any hardcore multiuser
testing. If more than one instance is created, my method of storing
logged in users will fail because each instance will have its own
hashtable.

So if that is the case, I figure I'll make the hashtable static. Does
anyone see any downside to this?

Thanks for your help

Nov 19 '05 #3
Brock,

Thanks for the reply. I'd like to use built in ASP.NET cache, but
since I am doing my processing in the AuthenticateRequest event, I was
under the impression that built in session and other caching mechinisms
are not available. Is this correct?

Nov 19 '05 #4
The data Cache is different from Session. You're right that in the AuthenticateRequest
event Session is not yet available, but the data Cache is. I'd use the data
Cache.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Brock,

Thanks for the reply. I'd like to use built in ASP.NET cache, but
since I am doing my processing in the AuthenticateRequest event, I
was under the impression that built in session and other caching
mechinisms are not available. Is this correct?


Nov 19 '05 #5

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

Similar topics

0
by: moid | last post by:
Sir we are implementing front controller in asp.net. we implement three event-handler 1. PreRequestHandlerExecute 2. PostRequestHandlerExecute 3. BeginRequest we just want to initialize...
2
by: Kenneth Myhra | last post by:
Hi, We have been trying to develop an IHTTPModule (that was supposed to replace or take over the ISAPI Filters, as far as we know). We have developed one in C# and it seems to be working. The...
2
by: Kenneth Myhra | last post by:
Hi, We are trying to make an authorization module for our web dav folder using ..NET and implementing the IHttpModule. We have already done this in a previous version of our product, with an...
2
by: Kenneth Myhra | last post by:
Hi all, We are trying to make an ISAPI Filter, in .NET by implementing the IHttpModule interface, that will authorize the request for certain binary file types (GET), this is working fine. But we...
5
by: Andrew Lippitt | last post by:
What gaurantees are there in the way of which thread the events are called from. I've seen: Thread A Begin Thread B Begin Thread A End Thread A End That seems to indicate that Begin and End...
6
by: Andy G | last post by:
I am trying to implement the global error handling described on this page... http://www.dotnetdevs.com/articles/GlobalErrorHandling.aspx I'm a VB person and don't understand much of C# when it...
6
by: Simone Busoli | last post by:
Hello, I am trying to understand when IHttpModule.Dispose method is called. Is it called when the Application is disposed, or when the request ends? If I want to make an object Application-wide...
8
by: =?Utf-8?B?UGhpbGlw?= | last post by:
When is the IHttpModule Dispose driven ?....at application recycle time ? I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and Dispose....and the Dispose never gets driven. ...
1
by: Eric Goforth | last post by:
Hello, I found a C# example on the web that used an httpmodule. I've translated it to VB.NET and the website compiles fine, but when I build the website the iHttpModule doesn't compile, I can't...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
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...
0
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...

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.