Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net core 2.2 using HttpCookieCollection in a class library

I am "upgrading" from old .net to .net core 2.2 (obviously it's not such as easy upgrade as it is a re-write)

This HttpCookieCollection is not so accessible anymore. For .Net Core 2.2 class library what are some examples of how to get access to this cookie collection?

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);
}

1 Answers

I believe the equivalent class would be IRequestCookieCollection

An instance of this object can be accessed in the request instance via HttpContext.Request.Cookies in a controller.

like image 125
Dan Avatar answered Nov 10 '25 00:11

Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!