It seems that the Global and Web.config files can both serve the same purpose for items like a connection string or general error messages. I was wondering what do most .NET developers choose to hold these settings? any good rule of thumb on this?
Global.asax isn't really used to store things like connection strings or global data. True, you can use it to modify application variables, but Global.asax is more of an event manager, where web.config is more of a configuration data store. Some of the
common events in Global.asax that are implemented are:
void Application_Start(object sender, EventArgs e)
{
//sometimes there is some initialization you'd
//like to do on application variables when
//the application starts (not, this doesn't
//typically work out to be once for an
//application's entire lifecycle. Server
//reboots and other things along those lines
//will cause this to happen too
}
void Session_Start(object sender, EventArgs e)
{
//A typical place to increment your current
//user count
int counter = Convert.ToInt32(Application.Get("numUserCount"));
counter++;
Application.Set("numUserCount", counter);
}
void Session_End(object sender, EventArgs e)
{
//A typical place to decrement your current
//user count
int counter = Convert.ToInt32(Application.Get("numUserCount"));
counter--;
Application.Set("numUserCount", counter);
}
void Application_Error(object sender, EventArgs e)
{
//Maybe you'd like to track your errors in a
//database?
}
void Application_End(object sender, EventArgs e)
{
//Maybe you can track application end
//events for performance monitoring
}
"Dream as if you'll live forever, live as if you'll die today." --James Dean
Marked as answer by defyant_2004 on Feb 17, 2009 08:18 PM
defyant_2004
Member
55 Points
337 Posts
Global vs Web.config
Feb 17, 2009 04:47 PM|LINK
It seems that the Global and Web.config files can both serve the same purpose for items like a connection string or general error messages. I was wondering what do most .NET developers choose to hold these settings? any good rule of thumb on this?
AceCorban
Star
12318 Points
2269 Posts
Re: Global vs Web.config
Feb 17, 2009 05:41 PM|LINK
Global.asax isn't really used to store things like connection strings or global data. True, you can use it to modify application variables, but Global.asax is more of an event manager, where web.config is more of a configuration data store. Some of the common events in Global.asax that are implemented are:
void Application_Start(object sender, EventArgs e) { //sometimes there is some initialization you'd //like to do on application variables when //the application starts (not, this doesn't //typically work out to be once for an //application's entire lifecycle. Server //reboots and other things along those lines //will cause this to happen too } void Session_Start(object sender, EventArgs e) { //A typical place to increment your current //user count int counter = Convert.ToInt32(Application.Get("numUserCount")); counter++; Application.Set("numUserCount", counter); } void Session_End(object sender, EventArgs e) { //A typical place to decrement your current //user count int counter = Convert.ToInt32(Application.Get("numUserCount")); counter--; Application.Set("numUserCount", counter); } void Application_Error(object sender, EventArgs e) { //Maybe you'd like to track your errors in a //database? } void Application_End(object sender, EventArgs e) { //Maybe you can track application end //events for performance monitoring }zullu
Member
18 Points
9 Posts
Re: Global vs Web.config
Apr 09, 2009 03:51 PM|LINK
Hi,
I have this global.asax file in my web service project. I have placed some code in the Application_Start and Session_Start events.
Now when I try to put a breakpoint in these two events and try to debug, I do not find my debug step breaking into these lines.
Instead it directly breaks into another class file method. Am I missing something.
Is there a better way to do this.
Thanks,
zullu
Global.asax event not firing Web service