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.