Asp.Net WebAPIにおけるCookie取得動作方式

1310 ワード

1.
/// <summary>
///        cookie
/// </summary>
/// <returns></returns>
[HttpGet]
[HttpPost]
public string GetOne()
{
    //1. WebApi       cookie     
    //2. WebApi        Form,QueryString         
    HttpCookieCollection collection= HttpContext.Current.Request.Cookies;

    //1.    context,   cookie     
    HttpContextBase baseContext = (HttpContextBase)Request.Properties["MS_HttpContext"];
    HttpCookieCollection cookie2 = baseContext.Request.Cookies;


    //2.api        cooki   
    Collection<CookieHeaderValue> cookieValues= Request.Headers.GetCookies();


    return CookieHelper.GetString("username");
}

 
apiのクッキー使用の詳細:
http://www.asp.net/web-api/overview/advanced/http-cookies