title: Read a cookie value set from a web api in an MVC controller
body: <p>I'm facing a problem with a Web Api and have a question:</p>
  
  <p>In MVC controller, I can't read a cookie value set from an Asp.Net Web Api.</p>
  
  <p>Web Api</p>
  
  <pre><code> [System.Web.Http.HttpPost]
   public System.Net.Http.HttpResponseMessage AddToCart(Interface.Models.CartModel CartModel)
      {
          HttpResponseMessage Response = null;
          try
          {
  
              // Do some thing
  
              Response = new HttpResponseMessage(HttpStatusCode.OK);
              var ShoppingCartDetailsCookie = new System.Net.Http.Headers.CookieHeaderValue("CartDetails", "value");
              ShoppingCartDetailsCookie.Domain = Request.RequestUri.Host;
              ShoppingCartDetailsCookie.Path = "/";
              ShoppingCartDetailsCookie.Expires = DateTime.Now.AddMinutes(2);
              Response.Headers.AddCookies(new System.Net.Http.Headers.CookieHeaderValue[] { ShoppingCartDetailsCookie });
  
  
              Response.Content = new System.Net.Http.ObjectContent&lt;Invoices&gt;(Cart, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
              return Response;
  
          }
          catch (Exception ex)
          {
              Log.RaiseError(ClassName, "AddToCart", ex);
              goto ThrowInternalServerError;
          }
  
      ThrowInternalServerError:
          Response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
          Response.Headers.Add("Message", Content.Shared.UnExpectedError);
          return Response;
      }
  </code></pre>
  
  <p>Controller
  public class SharedController : Controller
      {</p>
  
  <pre><code>    public ActionResult ShoppingCart()
      {
          if (Request.Cookies["CartDetails"] != null)
              {
                  var StrShoppingCartDetails = Request.Cookies["CartDetails"].Value;
                  //Do some thing
              }
  
  
          return PartialView("ShoppingCart", ShoppingCart);
      }
  
  }
  </code></pre>
  
  <p>I traced the cookie from chrome developer tool and found that the domain was set to ".domainname" rather than "domainname". Any suggestion?</p>