Please take your time to read the following, it's simple although the text
is 3 paragraphs...
Everytime an user is logged in I need to make a call to my sql server
database to grab some specific user settings and load into Session
variables. So, I have a "Loggedin" event in login.aspx which does this. As
users can be logged in (automatically) via HttpApplication & Cookies, I need
to run this same code after that. I can put the same code as above in this
particular event handler in my global.asax code but I want to have this code
stored in only one place although called from the above mentioned two
situations.
1) I store the custom code in global.asax, create a new global_asax class
from the login.aspx code and call the method. This means that every time an
user is logged in I have eaten up unneccesary amount of resources since the
new global_asax class resides in memory until destroyed (especially since
the code creates both SqlConnection and SqlDataReader objects). Also I'm
afraid I could run into thread-level clashes in case multiple requests are
using the global_asax code at same time (the SqlDataReader for example is
very sensitive here).
2) I have a custom "code" class e.g. "commons.cs" in my App_Code folder and
from global.asax and login.aspx create new instance of that class and call
the code. The same as above: this uses a lot of resources compared to a very
simple task.
....
I hope you get my point! Any ideas on how to solve this "smoothly", using
minimal resources and without storing the code.