Question

I'm trying to setup an Active Record web session per request in my WCF app. I included this in my web.config:

<httpModules>
      <add
          name="ar.sessionscope"
          type="Castle.ActiveRecord.Framework.SessionScopeWebModule, Castle.ActiveRecord" />
    </httpModules>

This was the recommended solution from the Castle docs:

http://www.castleproject.org/activerecord/documentation/trunk/usersguide/web.html

However it doesn't work, it gives me the error:

Could not load type 'Castle.ActiveRecord.Framework.SessionScopeWebModule' from assembly 'Castle.ActiveRecord'.

Did SessionScopeWebModule get moved? I'm using the latest AR dlls for .NET 4.

Était-ce utile?

La solution

Indeed SessionScopeWebModule was moved to a separate project named Castle.ActiveRecord.Web. This was done so that the main Castle.ActiveRecord assembly could be used in client profile targets.

So add a reference to Castle.ActiveRecord.Web.dll and change the type in the config to:

type="Castle.ActiveRecord.Framework.SessionScopeWebModule, Castle.ActiveRecord.Web"

Autres conseils

Note that the following works, even though the web.config solution does not:

public void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpContext.Current.Items.Add("ar.sessionscope", new SessionScope());
        }

        public void Application_EndRequest(object sender, EventArgs e)
        {
            try
            {
                var scope = HttpContext.Current.Items["ar.sessionscope"] as SessionScope;
                if (scope != null)
                    scope.Dispose();
            }
            catch (Exception ex)
            {
                HttpContext.Current.Trace.Warn("Error", "EndRequest: " + ex.Message, ex);
            }
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top