当我在其中运行我的方法时,global.asax
它不会运行,而当我使用IHttp
模块时它正在运行。请给任何建议。可能是因为:
context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);
是否可以在没有模块的情况下调用它?
代码示例:
我运行的方法:
public static void EndSession()
{
HttpContext context = HttpContext.Current;
if (context.Session != null)
{
ISession session = context.Session["Session"] as ISession;
if (context.Session["Session"] != null)
{
if (!session.Transaction.IsActive)
OpenTransaction(session);
session.Flush();
CommitTransaction(session);
session.Close();
context.Session["Session"] = null;
}
}
}
全球的:
private void Application_EndRequest(object sender, EventArgs e)
{
NhSessionHelper.EndSession();
}
IHTTP模块:
namespace MME.DAL.SesionManager
{
internal class SessionRequest : IHttpModule
{
#region Public Methods
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);
}
#endregion
#region Private Methods
private void Application_EndRequest(object sender, EventArgs e)
{
NhSessionHelper.EndSession();
}
#endregion
}
}