Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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# Webclient始终返回登录页面_C#_Asp.net_Login_Webclient - Fatal编程技术网

C# Webclient始终返回登录页面

C# Webclient始终返回登录页面,c#,asp.net,login,webclient,C#,Asp.net,Login,Webclient,我正在使用Webclient获取响应文本: String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery; String strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/"); WebClient client = new WebClient(); myresponse = client.D

我正在使用Webclient获取响应文本:

  String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
  String strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");

  WebClient client = new WebClient();
  myresponse = client.DownloadString(strUrl + "/handles/x.ashx");
但是,即使我已登录,响应仍然是登录页面


如何解决此问题?

“您”已登录到浏览器。
WebClient
未登录。它需要向服务器提供有效的会话cookie,以便模拟已登录的用户@乔恩,有没有更简单的方法让我从另一个页面获取文本?类似于Javascript中的ajax请求,如果用户登录,则无需再次设置会话cookie。如果有更简单的方法,有什么可以阻止用户在没有实际登录的情况下使用它查看页面内容?由于您不是通过浏览器进行交互,因此必须像浏览器一样手动进行交互。没有神奇的解决办法。