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

O

obeOnline

I'm getting the following error...

[WebException: The remote server returned an error: (401)
Unauthorized.]
System.Net.HttpWebRequest.CheckFinalStatus() +676
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult 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(strRootURI);

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.
 
B

bruce barker

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)


| I'm getting the following error...
|
| [WebException: The remote server returned an error: (401)
| Unauthorized.]
| System.Net.HttpWebRequest.CheckFinalStatus() +676
| System.Net.HttpWebRequest.EndGetResponse(IAsyncResult 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(strRootURI);
|
| 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.
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top