Hi All,
Any help would be much appreciated. It took long time to solve this issue. But I haven't got the solution.
In my ASP.NET web application,I used NHibernate.dll and configuration is read from the Web.config file as follows.
At Web.config
<httpModules>
<add name="CurrentSessionModule" type="Globals.CurrentSessionModule, Globals"/>
</httpModules>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.connection_string">Server=localhost;initial catalog=TESTDB;Integrated Security=SSPI</property>
<property name="current_session_context_class">web</property>
<property name="default_schema">dbo</property>
<mapping assembly="LAT.Domain"/>
</session-factory>
</hibernate-configuration>
At CurrentSessionModule.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using DataAccess;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
namespace Globals
{
public class CurrentSessionModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += delegate
{
string session = Global.SessionFactory.OpenSession();
CurrentSessionContext.Bind(session);
};
context.EndRequest += delegate
{
CurrentSessionContext.Unbind(Global.SessionFactory);
};
}
I reference this website(
http://dotnetslackers.com/articles/aspn ... P-NET.aspx)
but the main different between my project and the ref website is Global.asax
my Global.asax
<%@ Import namespace="System.Collections.Generic"%>
<%@ Import namespace="System.Xml"%>
<%@ Import namespace="System.IO"%>
<%@ Import namespace="System.Web.Configuration"%>
<%@ Application Language="C#" Inherits="Globals.LATApplication"%>
<script runat="server">
private static void LogData(string url, string httpSessionId, string Id)
{
if (!WebConfigurationManager.AppSettings["debugMode"].ToLower().Equals("none"))
try{
string fname = WebConfigurationManager.AppSettings["debugSessionLogFile"];
XmlDocument doc = new XmlDocument();
if (File.Exists(fname))
doc.Load(fname);
else
doc.LoadXml("<SessionLog><Statistics HttpSessions=\"0\" NHibernateSessions=\"0\"/><Entries/></SessionLog>");
XmlElement entry = doc.CreateElement("Entry");
doc.DocumentElement.GetElementsByTagName("Entries")[0].AppendChild(entry);
XmlAttribute att = doc.CreateAttribute("Time");
att.Value = DateTime.Now.ToString();
entry.Attributes.Append(att);
att = doc.CreateAttribute("Url");
att.Value = url;
entry.Attributes.Append(att);
XmlElement ele = doc.CreateElement("HttpSession");
ele.InnerText = httpSessionId;
entry.AppendChild(ele);
ele = doc.CreateElement("NHibernateSession");
ele.InnerText = Id;
entry.AppendChild(ele);
doc.Save(fname);
}
catch{}
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
if (!WebConfigurationManager.AppSettings["debugMode"].ToLower().Equals("none"))
{
string fname = WebConfigurationManager.AppSettings["debugSessionLogFile"];
try
{
if (File.Exists(fname))
File.Delete(fname);
}
catch { }
LogData("*Application Starting*", "*", "*");
}
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
LogData("*Application Ending*", "*", "*");
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
try
{
Exception ex = HttpContext.Current.Server.GetLastError();
string err = ex.Message;
string ierr = "";
if (ex.InnerException != null)
ierr = ex.InnerException.Message;
LogData("*Application Error*", "*" + err + "*", "*" + ierr + "*");
}
catch (Exception except)
{
LogData("*Application Error*", "*" + except.Message + "*", "*Application_Error Error*");
}
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
LogData("*Session Starting*", Session.SessionID, "*");
}
void Session_End(object sender, EventArgs e)
{
LogData("*Session Ending*", Session.SessionID, "*");
}
</script>
When I run the web application, I got the error " Illeglly attempt to associate a proxy with two open session".
I am not really sure how that would happen. I try some solution but haven't solved the issues.
Can anyone help me with this?
Regards
Su Hlaing