2

I'm working on an ASP.NET MVC project, exactly on a void method in a Controller, and I need to use HttpContext.Current.Request.Cookies but Visual Studio recognized Current as an error, and not shown ( Current ) in the Intilisense.

This is my method :

public void User_Access_Validation()
{

            var T_8 = HttpContext.Current.Request.Cookies["T_8"];
            var T_5 = HttpContext.Current.Request.Cookies["T_5"];
            var T_T = HttpContext.Current.Request.Cookies["T_T"];

            HttpContext.Current.Request.Cookie

            if (T_8 == null || T_5 == null || T_T == null)
            {
                response.Redirect("/Login");
            }
}

So please any help ?

5
  • have you added using System.Web; in class? Commented Jun 2, 2020 at 12:43
  • Yeah I added it Commented Jun 2, 2020 at 12:44
  • The method may be in the controller class, but it is not clear if the method is called from a controller action, where a HttpContext should be present - have you tried setting a breakpoint in the controller action you are accessing, and check if the HttpContext.Current is null there as well? Commented Jun 2, 2020 at 12:47
  • have you tried System.Web.HttpContext.Current? Commented Jun 2, 2020 at 12:54
  • Are you using .NET Core and not .NET Framework? Commented Jun 2, 2020 at 13:22

1 Answer 1

1

As vivek nuna Mentioned in his answer, you need to use System.Web.HttpContext.Current.Cookies["xxx"] when you need to work with Current in your case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.