NHibernate,HTTPApplication和Exceptions

时间:2013-08-14 18:43:01

标签: c# nhibernate asmx

我试图找到这个问题的答案,但我找不到任何明确的答案。 所以我的问题是,在我粘贴的代码中:

  • 以这种方式抛出异常是对的吗? (超级例外)
  • Dispose是否已被处理?
  • HTTPApplication会发生什么? (生命周期结束了吗?)

此代码在.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");
}

1 个答案:

答案 0 :(得分:1)

是的,using语句确保为给定对象调用Dispose(),请参阅documentation

HTTPApplication在其class documentation中记录事件顺序。即使面对未处理的异常,也会执行EndRequest事件。