Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Web.HttpContext.Current不存在_C#_Asp.net - Fatal编程技术网

C# System.Web.HttpContext.Current不存在

C# System.Web.HttpContext.Current不存在,c#,asp.net,C#,Asp.net,我正试图通过visual studio 2015在asp.net mvc应用程序中获取有关我的用户的一些信息 当我试图通过请求获取信息时 System.Web.HttpContext.Current req = new System.Web.HttpContext.Current(); 我收到一个错误错误CS0426类型“HttpContext”中不存在类型名“Current” 有人知道如何解决这个问题吗?如果您想获取当前上下文 System.Web.HttpContext curre

我正试图通过visual studio 2015在asp.net mvc应用程序中获取有关我的用户的一些信息

当我试图通过请求获取信息时

    System.Web.HttpContext.Current req = new System.Web.HttpContext.Current();
我收到一个错误
错误CS0426类型“HttpContext”中不存在类型名“Current”


有人知道如何解决这个问题吗?

如果您想获取当前上下文

System.Web.HttpContext currentContext = System.Web.HttpContext.Current;
如果您想创建一个(出于某种原因,如测试)


只需将
System.Web
引用添加到项目中,就可以了


使用System.Web也不会生成错误。

Current
是一个属性,而不是一个方法……一个静态属性,而不是一个类型。
var req=new System.Web.HttpContext.Current并且类型应该是HttpContexth否,如果整个问题是Current似乎不存在,我怎么办?!不,不是答案。这是不可能的,因为无论出于什么深不可测的原因,在HttpContext中都不存在Current。因此,您不能直接转到
System.Web.HttpContext currentContext=System.Web.HttpContext.Current
,因为Current不存在。我不知道它为什么不存在,这就是这里的问题。当我试图在MVC控制器操作中获取基本URL时,这对我来说是有效的。
System.Web.HttpContext newContext = new System.Web.HttpContext(
    new System.Web.HttpRequest("", "http://example.com", ""),
    new System.Web.HttpResponse(new System.IO.StringWriter())
    );