473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
2 8186
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
Thanks for shedding light on this issue for me.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris | last post by:
Hi, I try to download a file using the following : WebClient client = new WebClient(); client.Credentials = new NetworkCredential("Administrator", "test","MYPC");...
5
by: LOLO | last post by:
I want to save in a file the HTML code generated by a WebRequest to an aspx page. When a connect to a external site, i can obtain the html code generated by server. But when i connect to a page of...
1
by: Shiju Poyilil | last post by:
Hello everybody, I am using the the below mentioned packages for sending the mail, but when i assign the read file to a byte array " barr = wc.DownloadData(url)" I get an error "The remote...
1
by: Dave | last post by:
I'm trying to make a webrequest to another server on our webfarm (to synch the cache as explained in http://www.eggheadcafe.com/articles/20030420.asp) but I'm getting a 401 unauthorized error. ...
0
by: solex | last post by:
I am having some security issues with my web service The service uses the default credential cache to make a webDAV request to exchange to create an appointment. Using the browser the web...
0
by: David Davis | last post by:
I am setting up some collaboration software called eProject for a client. eProject is a web based asp application. During setup, the instructions called for registering a service called...
1
by: Rich | last post by:
When I try to publish my app I am now getting the 401 error message. It used to work. Then someone changed something on the server. We are now trying to change stuff back on the server. I don't...
5
by: archana | last post by:
Hi all, I am having application which is validating URL's and checking whether that URL is redirecting to some other URL at a time of opening or not. My code looks like:- WebRequest...
1
by: mfreeman | last post by:
I have a VB.NET 2005 Windows application that worked fine when I ran it a month ago, and now it is throwing an exception ("The remote server returned an error: (500) Internal Server Error.") and I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.