C# Visual Studio[ASP.NET MVC]无法识别HttpContext.Current
我正在做一个ASP.NET MVC项目,完全是在C# Visual Studio[ASP.NET MVC]无法识别HttpContext.Current,c#,asp.net,asp.net-mvc,httpcontext,C#,Asp.net,Asp.net Mvc,Httpcontext,我正在做一个ASP.NET MVC项目,完全是在控制器中的无效方法,我需要使用HttpContext.Current.Request.Cookies,但是Visual Studio将Current识别为错误,并且在Intilisense中未显示(Current) 这是我的方法: public void User_Access_Validation() { var T_8 = HttpContext.Current.Request.Cookies["T_8"];
控制器中的无效方法,我需要使用HttpContext.Current.Request.Cookies
,但是Visual Studio将Current
识别为错误,并且在Intilisense中未显示(Current
)
这是我的方法:
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");
}
}
因此,请提供任何帮助?正如他在回答中提到的,在您的案例中需要使用当前时,您需要使用System.Web.HttpContext.Current.Cookies[“xxx”]
。您是否添加了使用System.Web代码>在类中?是的,我添加了它方法可能在控制器类中,但不清楚该方法是否从控制器操作调用,其中应存在HttpContext-您是否尝试在正在访问的控制器操作中设置断点,并检查HttpContext.Current是否也为空?您是否尝试过System.Web.HttpContext.Current
?您使用的是.NET内核而不是.NET Framework?