0

I am using Webclient to get a response text:

  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");

However, even though I am logged in, the response is the login page.

How can I fix this?

enb081
  • 3,831
  • 11
  • 43
  • 66
  • "You" are logged in in the browser. The `WebClient` is not logged in. It would need to provide a valid session cookie to the server in order to impersonate a logged-in user. [Related](http://stackoverflow.com/questions/1777221/using-cookiecontainer-with-webclient-class). – Jon Apr 10 '13 at 09:05
  • @Jon Is there any simpler way I can get the text from another page? Something similar to the ajax request in Javascript, in which if the user is logged in, there is no need to set session cookies again. – enb081 Apr 10 '13 at 09:07
  • 2
    If there were any simpler way, what would prevent someone from using it to look at the contents of pages without actually logging in? Since you are not interacting through a browser, you must manually do like a browser does. There is no magic solution. – Jon Apr 10 '13 at 09:11

0 Answers0