开发者

application_error Server or HttpContext.Current.Server confusion

I am confused over whether to use

Server.GetLastError

or

HttpC开发者_如何学Pythonontext.Current.Server.GetLastError

in the Application_Error event.

Can someone please help me understand the differences between the two?

Thanks,

AJ


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜