Reputation: 5
I just started an asp.net mvc core project and for some reason when I try to use HttpCookieCollection in my controller method like below, I get "Type or Namespace Could not be found". I have imported System.Web also. What could be the issue?
public IActionResult Index()
{
HttpCookieCollection cookies = Request.Cookies;
return View();
}
Upvotes: 0
Views: 361
Reputation: 5032
In the asp.net core Request.Cookies
type is IRequestCookieCollection
and it's part of Microsoft.AspnetCore.Http
namespace!
So you must change your code to:
public IActionResult Index()
{
Microsoft.AspNetCore.Http.IRequestCookieCollection cookies = Request.Cookies;
var cookie = cookies["cookieKey"];
return View();
}
Upvotes: 1