asp.net core 2.2 在类库中使用 HttpCookieCollection

4 .net c# asp.net-core-mvc .net-core asp.net-core

我正在从旧的.net“升级”到.net core 2.2(显然这不是那么容易的升级,因为它是重写)

HttpCookieCollection不再那么容易接近了。对于 .Net Core 2.2 类库,有哪些示例说明如何访问此 cookie 集合?

private static string CollectionToHtmlTable(HttpCookieCollection collection)
{
    // Converts HttpCookieCollection to NameValueCollection
    var nvc = new NameValueCollection();
    foreach (string item in collection)
    {
        var httpCookie = collection[item];
        if (httpCookie != null)
        {
            nvc.Add(item, httpCookie.Value);
        }
    }

    return CollectionToHtmlTable(nvc);
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*Dan 5

我相信等效的课程是IRequestCookieCollection

HttpContext.Request.Cookies可以通过控制器在请求实例中访问该对象的实例。