title: Create Cookie ASP.NET & MVC
body: <p>I have a quite simple problem. I want to create a cookie at a Client, that is created by the server.
  I've found a lot of <a href="http://www.codeproject.com/Articles/244904/Cookies-in-ASP-NET" rel="nofollow noreferrer">pages</a> that describe, how to use it - but I always stuck at the same point.</p>
  <p>I have a <code>DBController</code> that gets invoked when there is a request to the DB.</p>
  <p>The <code>DBController</code>'s constructor is like this:</p>
  <pre><code>public class DBController : Controller
  {
      public DBController()
      {
          HttpCookie StudentCookies = new HttpCookie(&quot;StudentCookies&quot;);
          StudentCookies.Value = &quot;hallo&quot;;
          StudentCookies.Expires = DateTime.Now.AddHours(1);
          Response.Cookies.Add(StudentCookies);
          Response.Flush();
      }
  
      [... more code ...]
  
  }
  </code></pre>
  <p>I get the Error &quot;<em>Object reference not set to an instance of an object</em>&quot; at:</p>
  <pre><code>StudentCookies.Expire = DateTime.Now.AddHours(1);
  </code></pre>
  <p>This is a kind of a basic error message. So what kind of basic thing I've forgot?</p>