By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,081 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

WebRequest Error, the remote server returned an error: (401)

P: n/a
I'm getting the following error...

[WebException: The remote server returned an error: (401)
Unauthorized.]
System.Net.HttpWebRequest.CheckFinalStatus() +676
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
+139
System.Net.HttpWebRequest.GetResponse() +147
Web.WebDav.Page_Load(Object sender, EventArgs e)

[Exception: Failed!]
Web.WebDav.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731

Web.WebDav is my custom component. If I Terminal Service into the
server running the component and use IE, it works fine. If I access it
from the browser on my local PC, I get the (401) Unauthorized error.

Source Code:

// Variables.
System.Net.HttpWebRequest netRequest = null;
System.Net.WebResponse netResponse = null;

System.IO.Stream RequestStream = null;
System.IO.Stream ResponseStream = null;

// Configure the HttpWebRequest object.
netRequest =
(System.Net.HttpWebRequest)HttpWebRequest.Create(s trRootURI);

netRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Only works locally
//netRequest.Credentials = new
NetworkCredential("UserName","Password"); //Works everywhere

netRequest.Method = "SEARCH";
bytes = Encoding.UTF8.GetBytes((string)strQuery);
netRequest.ContentLength = bytes.Length;
RequestStream = netRequest.GetRequestStream();
RequestStream.Write(bytes, 0, bytes.Length);
RequestStream.Close();

netRequest.ContentType = "text/xml";
netRequest.Headers.Add("Translate", "F");

netResponse = (HttpWebResponse)netRequest.GetResponse();
ResponseStream = netResponse.GetResponseStream();
Details:
1. Authentication mode = Windows and impersonation = true.
2. Anonymous access is disabled and Integrated Windows authentication
enabled in IIS for the application.
3. If I replace netRequest.Credentials =
System.Net.CredentialCache.DefaultCredentials with
netRequest.Credentials = new NetworkCredential("UserName","Password"),
things work fine.
4. The request is to an Exchange Server (WebDav)
5. Same symptoms with the version running on my local pc. Works from
local browser, does not work from remote browser.
6. Server: 2K3 Server, Local: XPPro

PLEASE HELP. Thanks.

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you are hitting the one hop rule. the web service needs a primary token to
access exchange. you have a couple options.

1) use a standard service account for access
2) use basic authenication
3) use kerboeros authentication and enable creditals forwarding.

-- bruce (sqlwork.com)
"obeOnline" <ob*******@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
| I'm getting the following error...
|
| [WebException: The remote server returned an error: (401)
| Unauthorized.]
| System.Net.HttpWebRequest.CheckFinalStatus() +676
| System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
| +139
| System.Net.HttpWebRequest.GetResponse() +147
| Web.WebDav.Page_Load(Object sender, EventArgs e)
|
| [Exception: Failed!]
| Web.WebDav.Page_Load(Object sender, EventArgs e)
| System.Web.UI.Control.OnLoad(EventArgs e) +67
| System.Web.UI.Control.LoadRecursive() +35
| System.Web.UI.Page.ProcessRequestMain() +731
|
| Web.WebDav is my custom component. If I Terminal Service into the
| server running the component and use IE, it works fine. If I access it
| from the browser on my local PC, I get the (401) Unauthorized error.
|
| Source Code:
|
| // Variables.
| System.Net.HttpWebRequest netRequest = null;
| System.Net.WebResponse netResponse = null;
|
| System.IO.Stream RequestStream = null;
| System.IO.Stream ResponseStream = null;
|
| // Configure the HttpWebRequest object.
| netRequest =
| (System.Net.HttpWebRequest)HttpWebRequest.Create(s trRootURI);
|
| netRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
| //Only works locally
| //netRequest.Credentials = new
| NetworkCredential("UserName","Password"); //Works everywhere
|
| netRequest.Method = "SEARCH";
| bytes = Encoding.UTF8.GetBytes((string)strQuery);
| netRequest.ContentLength = bytes.Length;
|
|
| RequestStream = netRequest.GetRequestStream();
| RequestStream.Write(bytes, 0, bytes.Length);
| RequestStream.Close();
|
| netRequest.ContentType = "text/xml";
| netRequest.Headers.Add("Translate", "F");
|
| netResponse = (HttpWebResponse)netRequest.GetResponse();
| ResponseStream = netResponse.GetResponseStream();
|
|
| Details:
| 1. Authentication mode = Windows and impersonation = true.
| 2. Anonymous access is disabled and Integrated Windows authentication
| enabled in IIS for the application.
| 3. If I replace netRequest.Credentials =
| System.Net.CredentialCache.DefaultCredentials with
| netRequest.Credentials = new NetworkCredential("UserName","Password"),
| things work fine.
| 4. The request is to an Exchange Server (WebDav)
| 5. Same symptoms with the version running on my local pc. Works from
| local browser, does not work from remote browser.
| 6. Server: 2K3 Server, Local: XPPro
|
| PLEASE HELP. Thanks.
|
Nov 19 '05 #2

P: n/a
Thanks for shedding light on this issue for me.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.