MVC3 - IHttpModule, not working on production server

6 posts, 1 answers
  1. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 27 Feb 2012 Link to this post

    The OpenAccess setup where the database context object is stored in the Session is not working correctly on our production server. Is there something additional that needs to be configured to get this working? It works on dev machines.
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 28 Feb 2012 Link to this post

    Hi Scott,

    Storing the OpenAccessContext instance in the session state could lead to wrong behavior if there are multiple requests to a page or custom handlers which are using the same session. This could lead to a situation when one request disposes the context before other request are finished doing their work, which will cause an exception. Problems could arise when the application is being used in a web farm.

    Better approach is to store the context in the HttpContext.Items collection. You could find the sample application, deployed with the Product SDK, helpful. They demonstrate how to handle the context.

    Hope that helps.

    Kind regards,
    Damyan Bogoev
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
  3. DevCraft banner
  4. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 28 Feb 2012 Link to this post

    I got the MVC3 sample from the OpenAccess SDK that stores the context in the Session object... that's why i was doing it that way...

    I now see the other sample solution that stores it in the HttpContext.Items collection, and will change it over to that instead, will let you know if i continue to have issues with this method... Thanks!
  5. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 28 Feb 2012 Link to this post

    Ok, i switched over to using HttpContext.Current.Items, and again it works great on dev machine.... but as soon as I deploy out to production server, it stops working.

    I added some logging and found out that the ContextModule : IHttpModule is not even firing the Init... I attached my web.config file... I have the HttpModules section added... please help... thanks in advance! :)

    correction i attached screenshots of my web.config file since it doesn't allow anything else...
  6. Answer
    TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 29 Feb 2012 Link to this post

    Hi Scott,

    What is your production environment? IIS7 Integrated mode?

    If so,  modules should be registered in the system.webServer section of the web.config like:

    <configuration>
      <system.webServer>
        <modules>
          <add name="HelloWorldModule" type="HelloWorldModule"/>
        </modules>
      </system.webServer>
    </configuration>

    The system.web section is used for environments like IIS6 + II7 running classic mode.

    I always add things in both places, so that it will run in all environments...

    Let me know if it works out..

    Regards

    Henrik
  7. Scott
    Scott avatar
    68 posts
    Member since:
    Nov 2011

    Posted 02 Mar 2012 Link to this post

    That fixed it, thanks!
Back to Top
DevCraft banner