I have a Global.Asax and Global.Asax.cs file that is specific to my particular Asp.net project.
For some unknown reason the code in my Global.asax.cs file is not being executed. I thought that the
breakpoints were being ignored, however that is not the case. Because if I try to deliberately force
an error to occur, the code is never executed. Below is an example of what I am talking about. The real
code in my Application_Start method is not shown below. ANd other methods are not shown as well.
I have tried renaming the Global.asax file and then re-creating it, and that did not work either. Strange because
when I try and create a new Global.asax file, the option to create a code behind file is greyed out.
Can someone please help me out? Why isn't my Global.Asax.cs code being executed?
Remember that Application_Start only runs when the application starts for the first time. So if the Visual Studio Web Server is already running, and you've done nothing to cause the application to restart, then the code won't be rerun. One way to cause a
restart is to change web.config (just add a space somewhere and save it), or you can stop the web server and restart it.
And never rename global.asax. When you choose to add it, just leave the name as it shows. I've had that problem - when I tried changing the name upon creation, it never worked, but did when I deleted it and recreated with default name.
Marked as answer by brgdotnet on Jul 23, 2010 05:07 AM
brgdotnet
Participant
1202 Points
724 Posts
global asax.cs code is not executing
Jul 22, 2010 03:09 AM|LINK
I have a Global.Asax and Global.Asax.cs file that is specific to my particular Asp.net project.
For some unknown reason the code in my Global.asax.cs file is not being executed. I thought that the
breakpoints were being ignored, however that is not the case. Because if I try to deliberately force
an error to occur, the code is never executed. Below is an example of what I am talking about. The real
code in my Application_Start method is not shown below. ANd other methods are not shown as well.
I have tried renaming the Global.asax file and then re-creating it, and that did not work either. Strange because
when I try and create a new Global.asax file, the option to create a code behind file is greyed out.
Can someone please help me out? Why isn't my Global.Asax.cs code being executed?
private void Application_Start(object sender, EventArgs e)
{
int x = 1;
int y = 1;
int z=1/(x-y)
}
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: global asax.cs code is not executing
Jul 22, 2010 03:24 AM|LINK
if you put protected instead of private, does it work?
sanjibsinha
Contributor
5014 Points
947 Posts
Re: global asax.cs code is not executing
Jul 22, 2010 03:30 AM|LINK
You are attempting to divide by zero.
12reach: asp.net meets php
Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: global asax.cs code is not executing
Jul 22, 2010 08:23 AM|LINK
Remember that Application_Start only runs when the application starts for the first time. So if the Visual Studio Web Server is already running, and you've done nothing to cause the application to restart, then the code won't be rerun. One way to cause a restart is to change web.config (just add a space somewhere and save it), or you can stop the web server and restart it.
brgdotnet
Participant
1202 Points
724 Posts
Re: global asax.cs code is not executing
Jul 22, 2010 11:54 AM|LINK
Yes, Sanji
Please read my posts. I put in that code to illustrate the fact that the code is never executed.
brgdotnet
Participant
1202 Points
724 Posts
Re: global asax.cs code is not executing
Jul 22, 2010 11:56 AM|LINK
Hi Dave,
I will try your suggestion. I went as far as rebooting my machine yesterday and still that did not work. I will try changing the web.config file.
Bob
hoodedperson...
Star
12950 Points
3196 Posts
Re: global asax.cs code is not executing
Jul 22, 2010 12:55 PM|LINK
Good call. Do you remember what happens when you try to divide by zero?
hoodedperson...
Star
12950 Points
3196 Posts
Re: global asax.cs code is not executing
Jul 22, 2010 12:57 PM|LINK
You forgot a ";" on your third line (the line that divides). I'm not sure much will change, but I'm surprised it let you compile...
hoodedperson...
Star
12950 Points
3196 Posts
Re: global asax.cs code is not executing
Jul 22, 2010 01:03 PM|LINK
And never rename global.asax. When you choose to add it, just leave the name as it shows. I've had that problem - when I tried changing the name upon creation, it never worked, but did when I deleted it and recreated with default name.