MVC 4 with Castle Windsor IOC Controllers Session Is Null
<p>I have an MVC4 solution which has a separate project for the controllers. This all works fine.</p>

<p>I have now integrated Castle Windsor IOC as I have done many times before in single project solutions, and it seems to have registered properly as when my web site starts it calls into the HomeController with the repository dependencies just fine.</p>

<p>However all my controllers inherit a BaseController class (which inherits Controller naturally) and in the constructor of the BaseController I am accessing the Session object.</p>

<p>Post Castle Windsor this is no longer working. The Session object is null.</p>

<p>Here is the code from BaseController</p>

<pre><code>    protected BaseController(ICustomerRepository customerRepository, ISystemSettingsRepository systemSettingsRepository)
    {
        _customerRepository = customerRepository;
        _systemSettingsRepository = systemSettingsRepository;

        _timeoutMinutes = _systemSettingsRepository.GetSystemSettings().TimeoutMinutes;

        Session["KYCWarning"] = _customerRepository.GetMessage("KYCWarning");
    }
</code></pre>

<p>The reason I am storing this message in a Session variable is that it is used in a condition statement in a cshtml file</p>

<pre><code>@{
    var kycWarning = Session["KYCWarning"].ToString();
    var settingShowKYCReminder = ConfigurationManager.AppSettings["ShowKYCReminder"];
    var showKYCReminder = !string.IsNullOrWhiteSpace(settingShowKYCReminder) &amp;&amp; (bool.Parse(settingShowKYCReminder));
}

@if (showKYCReminder &amp;&amp; Session["CurrentSession"] != null &amp;&amp; !string.IsNullOrWhiteSpace(kycWarning) &amp;&amp; !((SessionModel)Session["CurrentSession"]).Customer.KycAuthorised)
{
    &lt;div class=""&gt;
        &lt;div class="col-md-12 WarningMessageBox"&gt;
            &lt;span&gt;@kycWarning&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
}
</code></pre>

<p>This is just one example, there are other uses of Session within the controllers and I expect they will fail to if the code were reachable past this exception.</p>

<p>Can anyone suggest why this is happening, and a solution? I understood that a controller that inherits the Controller class would always have access to Session.</p>

<p>Thank you.</p>