Checking Cookie for Value in ASP.NET results in an Object Reference Null Exception
<p>When I attempt to access a cookie, I get the following exception: </p>

<blockquote>
  <p>Object reference not set to an instance of an object.</p>
</blockquote>

<p>This is the line in question:</p>

<pre><code>if (Request.Cookies["selectBoxValue"].Value != null)
</code></pre>

<h3>Controller</h3>

<pre><code>[Authorize]
        public ActionResult Index()
        {
            if (Request.Cookies["selectBoxValue"].Value != null)
            {
                HttpCookie groupId = new HttpCookie("selectBoxValue");
                groupId = Request.Cookies["selectBoxValue"];

                // Collect all comments connected to current group
                int t = Convert.ToInt32(groupId.Value);
                pv.ListofComments = db.Comments.Where(dp =&gt; dp.GroupID == t).ToList();

                // Show only groups connected to current user
                var CurrentUser = User.Identity.GetUserId();
                var groupUser = db.GroupUsers.Where(u =&gt; u.ApplicationUserId == CurrentUser).Select(gr =&gt; gr.GroupId).ToList();
                pv.GroupList = db.Groups.Where(g =&gt; groupUser.Contains(g.Id));
                return View(pv);

        }
</code></pre>