ASP.NET customErrors with mode=remoteOnly and global.asax handling exceptions

Multi tool use
Multi tool use


ASP.NET customErrors with mode=remoteOnly and global.asax handling exceptions



I have custom errors set in the web config file as follows:


<customErrors mode="RemoteOnly" defaultRedirect="GenericError.aspx" />



Fine and dandy... I like that mode="RemoteOnly" facilitates development...



For unhandled exceptions, I have in global.asax:


Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("GenericError.aspx")
End Sub



However, unhandled exceptions are going to the generic error page instead of the informative yellow screen of death preferred by developers. I can comment out the redirect in global.asax, but then I need to remember to change it for the production environment. Is there a way I can check in Application_Error whether I am remote or not to determine whether to redirect?




2 Answers
2



You do not need the Response.Redirect in the Global.asax. It duplicates the behaviour of the <customErrors> tag. RemoteOnly will give end users the custom error message and local usrs the standard asp.net error page. If your developers use a local web server for development you have both in one.


Response.Redirect


<customErrors>



Another approach is to set the <customErrors> to Off on development servers and set it to On in the production environment. There are usually many items in the web.config that need changing so it is no more of a hardship.


<customErrors>


Off


On





You are right, I must have had a brain fart for not understanding!
– harrije
Jul 19 '10 at 16:57



You shouldn't even need the line in Application_Error if you have the defaultRedirect set in your web.config.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

irr27G5 H7Kz
Z,F0IV9O,ysgNkjoSB6NWpv,2x9 diYap TunrP5U6 DpyrZKbJ,dbF3,ael3ZPejPpAnBExFXJM6gIU

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications