Search code examples
c#.net-coresetcookie

Setting up cookie options


Creating simple method and seems like the 'cookieOptions' function are not working and Im getting stack on its reference prerequisites.

May I know what reference or module needs to be import to enable the capability of this

Here is the sample method:

public void SetCookie(string key, string value, int? expireTime)
{
    CookieOptions option = new CookieOptions(); /// => Missing reference here      
}

And here is the returning error:

'CookieOptions' could not be found (are you missing a using directive or an assembly reference?)

Any suggestions/comments TIA


Solution

  • I'm assuming that you are using net core (nothing like this in .net framework)

    Namespace:

    Microsoft.AspNetCore.Http

    Assembly:

    Microsoft.AspNetCore.Http.Features.dll

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.cookieoptions?view=aspnetcore-3.0