AJ.
AJ.

Reputation: 11240

application_error Server or HttpContext.Current.Server confusion

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

Upvotes: 3

Views: 706

Answers (1)

vcsjones
vcsjones

Reputation: 141638

You should be using Server.GetLastError from the HttpApplication. In most cases, they are the same thing. Most ASP.NET base classes support the Server property as a shortcut to the current HttpContext's Server (Such as HttpApplication and Page). However, for the case of HttpApplication, if you are in a place where there is no HttpContext, it will create a new Server utility for you. For the case of Page and UserControl, they are exactly the same thing since you will always have an HttpContext no matter where you are in the life cycle.

Upvotes: 5

Related Questions