RE: 401.1 Error when calling an asp.net page from code.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Nevermind. This turned out to be the loopback check issue:
http://support.microsoft.com/kb/896861

We opted for method 2.

"blevitt" wrote:

aspx page A and aspx page B are on the same server. I'm using the code below
in aspx page A to call aspx page B. This works fine in our qa and dev
environments but fails in our production environment. Using the default
credentials also works in dev and qa. In production, the
httpRequest.GetResponse() call throws an error and looking at the
WebException response it shows page be responded with:
HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials.

If I connect to page B directly it works fine (even if using the same
credentials I'm using in code). When using DefaultCredentials I thought that
I had an NTLM double hop issue, but adding credentials voids that I think.
I'm running out of ideas. The only other difference on this box that I'm
aware of is that it is load balanced (although at the moment it only has one
node).

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(helperURL);
httpRequest.Credentials = new NetworkCredential("username", "password");
//httpRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
//httpRequest.UseDefaultCredentials = true;
//httpRequest.PreAuthenticate = true;

StreamReader reader;
XmlDocument xmlDoc = new XmlDocument();
try
{
using (HttpWebResponse httpResponse =
(HttpWebResponse)httpRequest.GetResponse())
{
reader = new StreamReader(httpResponse.GetResponseStream());
xmlDoc.Load(reader);
}
}
catch (System.Net.WebException ex)
{
throw new ApplicationException(
"Data helper threw http 500 error:\r\n"
+ DumpHttp(httpRequest, ex.Response)
);
}

.



Relevant Pages

  • Re: Authentication/Impersonation Inconsistency
    ... Each of the files having only 1 different user given> permission. ... > 1) Sometimes things happen as expected where, when moving from apsx to aspx,> I get promted for the username/password/domain and with the proper> credentials get permission. ... But all of a sudden it stops working and am not> given access when retrying with the same credentials on the same aspx page> when nothing has changed. ... > 2) When provided access via the username/login/domain credentials all other> pages that are accessed use that last set of credentials instead of the> original, that being what the user is logged into the machine as. ...
    (microsoft.public.dotnet.security)
  • Re: saving files in a remote computer
    ... Regards ... Matjaz Ladava ... > I have an .aspx that makes several operations and at the ... > impersonation and saving credentials in the registry, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • saving files in a remote computer
    ... I have an .aspx that makes several operations and at the ... end saves a XML file with all the information obtained ... I was reading an article in MSDN about ASP.NET ... impersonation and saving credentials in the registry, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Passing user credintials from a web page to a web service.
    ... >running on a different server than the web service, ... >credentials are that of the IIS server running the aspx. ... >> Hi Dan, ...
    (microsoft.public.dotnet.framework.aspnet)
  • 401.1 Error when calling an asp.net page from code.
    ... aspx page A and aspx page B are on the same server. ... Access is denied due to invalid credentials. ... StreamReader reader; ... XmlDocument xmlDoc = new XmlDocument; ...
    (microsoft.public.inetserver.iis)