|
Home > Archive > IIS Server Security > April 2005 > 401 Error using HttpWebRequest in .NET
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
401 Error using HttpWebRequest in .NET
|
|
| Ryan.Melena@gmail.com 2005-04-27, 5:57 pm |
| 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
| |
| Stefan Cuypers 2005-04-27, 5:57 pm |
| Ryan,
You might try to disable the loopback test in Windows 2003SP1. This helped
for me for a similar behaviour.
For details see Microsoft KB896861 at
http://support.microsoft.com/defaul...kb;en-us;896861
Stefan.
<Ryan.Melena@gmail.com> wrote in message
news:1114615605.221290.177140@g14g2000cwa.googlegroups.com...
> 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
>
|
|
|
|
|