title: How to set and return session id in headers in web api2
body: <p>After successful login I want to return <code>session_id</code> in response headers and along with that some object I want to return.</p>
  
  <p>My typical response header is as follows.</p>
  
  <pre class="lang-none prettyprint-override"><code>Response
  Header: Set-cookie: session_id=121212-343dsfsd-4323132, path=/, expires: 1212
  Body: {
      “status”: 0,
      “data”: {
          “userRole”: “SUPER_ADMIN”
      }
  }
  </code></pre>
  
  <p>I am trying as below to achieve above.</p>
  
  <pre><code>bool result = //...validate username and password with database
  
  if(result == true)
  {
      SessionIDManager manager = new SessionIDManager();
      string newSessionId= manager.CreateSessionID(HttpContext.Current);
      var resp = new HttpResponseMessage();
      var cookie = new CookieHeaderValue("session-id",newSessionId);
      cookie.Expires = DateTimeOffset.Now.AddDays(1);
      cookie.Domain = Request.RequestUri.Host;
      cookie.Path = "/";
      resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });
      //return resp;
      obj.UserRole = (from c in entityObject.NCT_UserRegistration where obj.User_Name == c.User_Name &amp;&amp; obj.User_Password == c.User_Password select c.User_Role).FirstOrDefault();
      obj.Success = 0;
      obj.User_Password="";
      return Ok(obj);
  }
  </code></pre>
  
  <p>I am not sure the way I followed correct or not. How can I return <code>sessionid</code> as above?</p>