5

I am having hard time in executting an On_Error event in Global.asax file. When the application gets error ,it should go to Global.asax file , log the error in database and redirect to custom error page. The above code working fine in my local,but once i deploy the same in DEV machine the Global.asax is not being executed.

It always redirects to the custome error page i mentioned in the web.config

<customErrors mode="On" defaultRedirect="/Error_Redirect.asp">
        <error statusCode="404" redirect="/404.asp"/>
    </customErrors>

The project structure in IIS is like Test1 \ Test 2 . The error handling code i am trying is in Test 2 and its a virtual diectory in the IIS.If i have any error in web.config file, like "Section already mentioned " ,then error is hitting the Global.asax file. If there is any runtime errors like below ,it is not coming to Global.asax file.

Int32 i, j, k;
i = 10;

j = 0;

k = i / j;

Response.Write(k);

. I even tired setting the mode to Off / RemoteOnly. Any suggestions??

Thanks,

Vani
  • 1,345
  • 4
  • 27
  • 48
  • Maybe this helps: http://stackoverflow.com/questions/5604144/application-error-does-not-fire – Tim Schmelter Feb 15 '12 at 20:15
  • @Tim I tried those options. But it looks like Global.asax firing is inconsistent. Sometimes its hitting Global.asax file ,but not constant. Wondering if its anything to do with IIS setting. – Vani Feb 17 '12 at 21:54
  • Don't you mean the Application_Error event? It only fires the event if customErrors mode="Off". – Eric H Feb 27 '12 at 18:43
  • Eric... I tried that too. The customErrors mode="Off" , but stil the errors are not hitting the Global.asax. – Vani Feb 27 '12 at 18:50
  • Are you setting the Test 2 project global.asax and web config? – Özgür Kara Feb 29 '12 at 22:35
  • I noticed that in your web.config, you've omitted the "x" from `"/Error_Redirect.asp"` and from the 404 - `redirect="/404.asp"`. Is that intentional? If so, have you tried setting it to a static (html) or asp.net (aspx) extension? – Josh E Mar 05 '12 at 15:26
  • @Kara yea i am seetting the Test 2 project global.asax and web.config – Vani Mar 14 '12 at 19:47
  • @Josh E i tried with aspx also .. no luck – Vani Mar 14 '12 at 19:48

3 Answers3

2

You should try and drop the file precompiledapp.config from root. (at least temporarily rename it)

Har
  • 4,864
  • 2
  • 19
  • 22
1

Your browser can cache the redirect. try to modify the URL slightly to be different. Like adding ?something after your current URL, then you can be sure it's not cached in your browser.

Or you can also try ctrl shift delete in your browser to delete your cache.

If you need to be sure your global asax is going you can use something like this in your event hadler inside of global.asax file.

HttpContext.Current.Response.Write("TEST");
HttpContext.Current.Response.End();
Jiří Herník
  • 2,412
  • 1
  • 25
  • 26
0

Is there any chance that your application is getting loaded into multiple ASP.NET processes or domains? As you are using "Test1/Test2" do you think that by any chance some times a URL you call goes via "Test1/Test2" and sometimes via "Test2"?

Recently, I was working on an POC in ASP.NET and by mistake moved the Global.asax into a sub-folder rather than the root of the application. I was expecting some code in Application's start event to fire - which never did get fired. After moving it back to the root of the application, this started to work as expected.

So, when you call via "Test2" your Global.asax's exception handler fires while when you call via "Test1/Test2" then your Global.asax does not fire.

Dhwanil Shah
  • 1,072
  • 1
  • 9
  • 25
  • My folder structure is like FolderA/FolderB .The Folder B contains the .aspx.cs [file which contains the error] and the global.asax file. – Vani Mar 22 '12 at 18:53