title: How can I create session inside views in asp.net mvc?
body: <pre><code>@{
  ViewBag.Title = "Login";
  }
  
  &lt;h2&gt;Login&lt;/h2&gt;
  
  @Session["username"]="shahed";
  @Session["password"]="123";
  &lt;div style="height:200px;width:500px;background-color:red;"&gt;
  
       &lt;h3&gt;@Session["username"].ToString()&lt;/h3&gt;
  
  &lt;/div&gt;
  @Html.ActionLink("Logout", "Logout", "Login")
  </code></pre>
  
  <p>this code throw an exception while creating session in views.But i can create session in action of controller.</p>