title: Can't retrieve C# cookies from angular
body: <p>I am sharing a cookie value from one request to another in .net web api as mentioned bellow,</p>
  
  <p>1st Request :-</p>
  
  <pre><code>[HttpGet]
  [Route("api/MyAttendance/loginTask")]
  public async Task&lt;string&gt; loginTask()
  {    
      //some code
  
      DateTime now = DateTime.Now;
  
      HttpCookie cookie = new HttpCookie("userAuth");
  
      cookie["sessionId"] = sessionID;
      HttpContext.Current.Response.Cookies.Add(cookie);
      cookie.Expires = now.AddYears(50);    
  
      return "Successful";
  }
  </code></pre>
  
  <p>2nd Request :-</p>
  
  <pre><code>        [HttpGet]
          [Route("api/MyAttendance/GetUser")]
          public string GetUser()
          {
  
              HttpCookie cookie = HttpContext.Current.Request.Cookies["userAuth"];
              var sessionId = cookie["sessionId"];
  
              //some code
  
              return sessionId;   
          }
  </code></pre>
  
  <p>When I access the 1st request, the <code>sessionID</code> will be stored in the <code>httpcookie</code> so that I can get this cookie value from the 2nd request.I can do this process successfully from the .net web api(backend)and from postman.but when I do the same process from the angular(frontend),1st request works successfully but 2nd request will not execute it gives me following error because cookie value cannot be accessed.</p>
  
  <blockquote>
    <p>System.NullReferenceException: Object reference not set to an instance
    of an object.</p>
  </blockquote>
  
  <p>Calling Requests from the angular project(Frontend) :-</p>
  
  <pre><code> getAuthentication(): Observable&lt;any[]&gt; {
      return this._http.get('http://localhost:2073/api/MyAttendance/loginTask').pipe(
        map((response: Response) =&gt; &lt;any[]&gt;response.json()));
    }
  
    getUserData(): Observable&lt;any&gt; {
      return this._http.get("http://localhost:2073/api/MyAttendance/GetUser").pipe(
        map((response: Response) =&gt; &lt;any[]&gt;response.json()));;
    }
  </code></pre>
  
  <p>I have no idea about this problem.Can someone explain me how to resolve this? </p>