Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:38:59+00:00 2026-05-22T17:38:59+00:00

I use Windor Castle to wrap the HttpContext into a HttpContextWrapper via a factory

  • 0

I use Windor Castle to wrap the HttpContext into a HttpContextWrapper via a factory method.

container.Register(
    Component.For<HttpContextBase>()
        .LifeStyle.PerWebRequest
        .UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));

I have a class called SessionStorage which accesses HttpContext.Current.Session. I register it this way:

container.Register(
    Component.For<ISessionStorage>()
    .LifeStyle.PerWebRequest
    .ImplementedBy<HttpSessionStorage>());

The HttpSessionStorage class:

public class HttpSessionStorage : ISessionStorage
{
    public HttpContextBase httpContext { get; set; }

    public void Remove(string key)
    {
        httpContext.Session.Remove(key);        
    }

    public T Get<T>(string key)
    {
        return (T)httpContext.Session[key];
    }

    public void Set<T>(string key, T value)
    {
        httpContext.Session[key] = value;
    }
}

When I use it this way, then in about 40% of the cases the Session property is null and only if the requests are at a very high rate.

The strange thing is that if I use HttpContext.Current instead of httpContext, it works in all cases.

public class HttpSessionStorage : ISessionStorage
{
    public HttpContextBase httpContext { get; set; }

    public void Remove(string key)
    {
        HttpContext.Current.Session.Remove(key);        
    }

    public T Get<T>(string key)
    {
        return (T)HttpContext.Current.Session[key];
    }

    public void Set<T>(string key, T value)
    {
        HttpContext.Current.Session[key] = value;
    }
}

It has something to do with Windsor Castle but I can’t find the problem. I registered everything I can as PerWebRequest (except a NHibernate session factory).

Does someone have an idea what else I could check?

Lg
warappa

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:38:59+00:00Added an answer on May 22, 2026 at 5:38 pm

    OK, it wasn’t due to inproper Castle Windsor registration but something simpler: I accessed Session at a time when it’s not garanteed to be fully initialized – dummy me!

    My solution was to move the Session accessing code from Application_BeginRequest to Application_AcquireRequestState like pointed out here.

    Note:
    Maybe this code should be moved into a base controller – in OnAuthorization (edit: it works!).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Castle Windsor as my IoC container . I have an application that
I'm currently making use of Castle Windsor version 2.1 as my container and would
I'm using Castle Windsor and Binsor to use dependency injection in my application. I'm
I looked at this and it answers half my questions: Castle Windsor: Register class
Are there any simple examples on how to use Castle Windsor's Automatic Transaction Management?
Simple question. How do I use UnitOfWork with Castle.Windsor, nHibernate, and ASP.NET MVC? Now
How can I use Windsor in my .net 3.5 solution? Can I use the
I use $(window).bind( ... ) to set up event handlers, but for some reason
Under VS's external tools settings there is a Use Output Window check box that
I can use FlashWindowEx to make a window flash in the taskbar, but what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.