I am confused over whether to use
Server.GetLastError
or
HttpContext.Current.Server.GetLastError
in the Application_Error event.
Can someone please help me understand the differences between the two?
Thanks,
AJ
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be using
Server.GetLastErrorfrom the HttpApplication. In most cases, they are the same thing. Most ASP.NET base classes support theServerproperty as a shortcut to the current HttpContext’s Server (Such asHttpApplicationandPage). However, for the case ofHttpApplication, if you are in a place where there is no HttpContext, it will create a new Server utility for you. For the case ofPageandUserControl, they are exactly the same thing since you will always have an HttpContext no matter where you are in the life cycle.