我试图找到这个问题的答案,但我找不到任何明确的答案。 所以我的问题是,在我粘贴的代码中:
此代码在.NET 2.0 Web服务中执行。
[WebMethod]
[SoapHeader ("Credentials", Required=true)]
public void DoSomething ()
{
if (AuthenticationModule.IsValid (Credentials) && AuthenticationModule.CanPerformAction (Credentials, Permissions.DoSomething)) {
using (ISession session = NHibernateUtil.SessionFactory.OpenSession()) {
if(Condition)
throw new ApplicationException("Super exception");
session.Close ();
}
}
else
throw new SecurityException("Invalid user or inssuficient privileges");
}
答案 0 :(得分:1)
是的,using
语句确保为给定对象调用Dispose(),请参阅documentation。
HTTPApplication在其class documentation中记录事件顺序。即使面对未处理的异常,也会执行EndRequest事件。