user9883821
user9883821

Reputation: 5

ASP.NET MVC Core Visual Studios Mac: Type or Namespace Could not be found

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

Answers (1)

Majid Parvin
Majid Parvin

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

Related Questions