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,

8
  • Maybe this helps: stackoverflow.com/questions/5604144/… Commented Feb 15, 2012 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
    Commented Feb 17, 2012 at 21:54
  • Don't you mean the Application_Error event? It only fires the event if customErrors mode="Off".
    – Eric H
    Commented Feb 27, 2012 at 18:43
  • Eric... I tried that too. The customErrors mode="Off" , but stil the errors are not hitting the Global.asax.
    – Vani
    Commented Feb 27, 2012 at 18:50
  • Are you setting the Test 2 project global.asax and web config? Commented Feb 29, 2012 at 22:35

3 Answers 3

2

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

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();
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.

1
  • 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
    Commented Mar 22, 2012 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.