title: How to access session from a view in ASP .NET Core MVC 1.0
body: <p>I am trying to access session data from inside a view.</p>
  
  <p><strong>Use Case:</strong> I'm storing status messages in the session that will be displayed at the top of the page. Currently I implemented this by using a <code>DisplayMessages()</code> function that sets some <code>ViewData[....]</code> properties and calling it at the beginning of every controller action.</p>
  
  <p><strong>Goal:</strong> I want to only set the status message once without needing additional code in the controller to display the messages on the next page load.</p>
  
  <p>So I'm trying to access the messages that are stored in the session directly from the view.</p>
  
  <p>So far I have tried the following:</p>
  
  <ul>
  <li><em>Dependency Injection</em> of an IHttpContextAccessor (doesn't seem to work anymore with ASP .NET Core MVC 1.0.0</li>
  <li><a href="https://stackoverflow.com/a/37800274/1717115">Creating a static class to access the session</a>, including the change from <code>next()</code> to <code>next.invoke()</code> suggested in the comment
  
  <ul>
  <li>This didn't work. I could access the <code>HttpContext</code> and <code>Session.IsAvailable</code> was true, but there was no data in the session.</li>
  </ul></li>
  </ul>