401 Error using HttpWebRequest in .NET
Ryan.Melena_at_gmail.com
Date: 04/27/05
- Next message: alexk: "exporting key"
- Previous message: Matze: "Problem with Integrated Windows authentication on SSL connection - second times"
- Next in thread: Stefan Cuypers: "Re: 401 Error using HttpWebRequest in .NET"
- Reply: Stefan Cuypers: "Re: 401 Error using HttpWebRequest in .NET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 27 Apr 2005 08:26:45 -0700
Hello all,
I'm experiencing a very sporadic error since our company upgraded our
intranet server to IIS6 (win2k3 sp1). The problem is stemming from an
HttpWebRequest made in one of my .NET applications which is attempting
to include the contents of a web page in an email. I have attempted
sending credentials in different ways as shown below (both of which
worked without problem on IIS5 and win2k):
<CODE>
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webRequest.PreAuthenticate = true;
// Way 1:
webRequest.Credentials = CredentialCache.DefaultCredentials;
// Way 2:
webRequest.Credentials = new
NetworkCredential("username","password","domain");
HttpWebResponse webResponse =
(HttpWebResponse)webRequest.GetResponse();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
</CODE>
In both cases many requests are successful and the e-mail is sent
without a hitch. Other times, however, the request fails with a 401
error and an exception is thrown. Examples of the log file for each
case are shown below (HttpWebRequests followed by POST of page making
the request).
<SUCCESS>
2005-04-27 13:32:51 172.22.2.42 GET
/Apps/JobCreate/jobdetails_popup.aspx jobid=3030 80 - 172.22.2.42 - 401
2 2148074254
2005-04-27 13:32:51 172.22.2.42 GET
/Apps/JobCreate/jobdetails_popup.aspx jobid=3030 80 EGAN\rjm
172.22.2.42 - 200 0 0
2005-04-27 13:32:51 172.22.2.42 POST /Apps/JobCreate/index.aspx - 80
EGAN\gdp 172.22.2.104
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.1.4322)
200 0 0
</SUCCESS>
<FAILURE>
2005-04-27 14:58:22 172.22.2.42 GET
/Apps/JobCreate/jobdetails_popup.aspx jobid=3033 80 - 172.22.2.42 - 401
1 0
2005-04-27 14:58:22 172.22.2.42 GET
/Apps/JobCreate/jobdetails_popup.aspx jobid=3033 80 - 172.22.2.42 - 401
1 2148074252
2005-04-27 14:58:22 172.22.2.42 POST /Apps/JobCreate/index.aspx - 80
EGAN\sks 172.22.4.116
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0) 200 0 0
</FAILUR>
As can be seen from the log file, the same page is being requested in
every case (with only a different parameter in the URL). There are no
errors on the page being requested as it can be visited directly
without a problem.
The IIS Application is set to allow Integrated Windows Authentication
only (because I need to grab the user's login name for other purposes).
The problem does not seem to be linked to any particular user or
computer which is the thing that is really confusing me. It seems to
happen almost at random.
Any help that anyone could offer would be greatly apprecaited!
Thank you,
Ryan
- Next message: alexk: "exporting key"
- Previous message: Matze: "Problem with Integrated Windows authentication on SSL connection - second times"
- Next in thread: Stefan Cuypers: "Re: 401 Error using HttpWebRequest in .NET"
- Reply: Stefan Cuypers: "Re: 401 Error using HttpWebRequest in .NET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|