Re: ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

From: Colin Bowern (colin.bowern_at_nospam.indimensions.com)
Date: 01/02/04


Date: Fri, 2 Jan 2004 16:48:42 -0500

Just a quick follow up, I should note that it works when I manually pass
credentials:

Dim myCreds As New NetworkCredential("myuser", "mypassword", "mydomain")
Dim myCache As New CredentialCache
myCache.Add(New Uri("http://dev.mydomain.net/"), "Basic", myCreds)
resolver.Credentials = myCache

But I don't want to have to embed credentials in code, which is why I was
hoping Basic/Windows Authentication would take care of the issue. The
virtual directory holding the application has anonymous authentication
turned off.

Cheers!
Colin

"Colin Bowern" <colin.bowern@nospam.indimensions.com> wrote in message
news:...
> I'm trying to write an ASP.NET page that does on-the-fly XML/XSL
> transformation. The code is as follows:
>
> ---
> Dim xmlPath As String = Request.QueryString("xml")
> Dim xslPath As String = Request.QueryString("xsl")
>
> If (Len(xmlPath) <= 0) Or (Len(xslPath) <= 0) Then
> Response.Write("xml or xsl query string parameter missing")
> Response.End()
> End If
>
> Dim xtr As New XmlTextReader(xmlPath)
> Dim resolver As XmlUrlResolver = New XmlUrlResolver
> Dim doc As New XmlDocument
>
> resolver.Credentials = CredentialCache.DefaultCredentials
> xtr.XmlResolver = resolver
> doc.Load(xtr)
>
> Dim transform As New XslTransform
> transform.Load(xslPath, resolver)
>
> transform.Transform(doc, Nothing, Response.Output, resolver)
> ---
>
> When I run this on my local dev box and request an xml document and xsl
> stylesheet page from our development server which is running Windows
> SharePoint Services it works great. When I publish the application to the
> development server it doesn't seem to work. Instead I'm getting:
>
> ---
> Server Error in '/tools/transformxml' Application.
> --------------------------------------------------------------------------

--
> ----
>
> The remote server returned an error: (401) Unauthorized.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.Net.WebException: The remote server returned an
> error: (401) Unauthorized.
>
> Source Error:
>
> Line 39:         resolver.Credentials = CredentialCache.DefaultCredentials
> Line 40:         xtr.XmlResolver = resolver
> Line 41:         doc.Load(xtr)
> Line 42:
> Line 43:         ' Instantiate the XslTransform Object
>
>
> Source File: c:\inetpub\devroot\tools\transformxml\inline.aspx    Line: 41
>
> Stack Trace:
>
> [WebException: The remote server returned an error: (401) Unauthorized.]
>    System.Net.HttpWebRequest.CheckFinalStatus() +676
>    System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +139
>    System.Net.HttpWebRequest.GetResponse() +147
>    System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials
> credentials) +65
>    System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
> credentials) +94
>    System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
> ofObjectToReturn) +55
>    System.Xml.XmlTextReader.CreateScanner() +384
>    System.Xml.XmlTextReader.Init() +23
>    System.Xml.XmlTextReader.Read() +530
>    System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
> preserveWhitespace) +80
>    System.Xml.XmlDocument.Load(XmlReader reader) +72
>    ASP.inline_aspx.__Render__control1(HtmlTextWriter __output, Control
> parameterContainer) in
c:\inetpub\devroot\tools\transformxml\inline.aspx:41
>    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +27
>    System.Web.UI.Control.Render(HtmlTextWriter writer) +7
>    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
>    System.Web.UI.Page.ProcessRequestMain() +1929
>
>
> --------------------------------------------------------------------------
--
> ----
> Version Information: Microsoft .NET Framework Version:1.1.4322.573;
ASP.NET
> Version:1.1.4322.573
> ---
>
> Checking out the IIS logs I that the code is making a request to the page
> without any credentials.  Notable entries in the web.config include:
>
> ---
> <authentication mode="Windows" />
> <identity impersonate="true" />
> <authorization>
>  <deny users="?" />
> </authorization>
> ---
>
> I've got through KB article 306158 and I still can't seem to resolve this
> issue.  Any thoughts on what might prevent the XmlTextReader from pulling
> the document?
>
> Thanks!
> Colin
>
>


Relevant Pages

  • Re: ADSI Impersonation Problem
    ... credentials to access Active Directory. ... matches the NetBIOS name of the machine. ... Execute it by Domain User on the Domain joined PC, the script works. ... Dim ComputerName ...
    (microsoft.public.windows.server.active_directory)
  • mailer doesnt send till program ends
    ... dim emailsas string ... 'Now we 've got everything we need to send the email except an SMTP server. ... 'Because gmail requires authentication to send a message we need to tell it ... about the credentials we set up earlier. ...
    (microsoft.public.inetserver.iis.smtp_nntp)
  • vb emailer doesnt send till program ends
    ... The code below works to send email through my email system. ... dim emailsas string ... 'Because gmail requires authentication to send a message we need to tell it ... about the credentials we set up earlier. ...
    (microsoft.public.vb.general.discussion)
  • The remote server returned an error: (401) Unauthorized
    ... Dim errDataSet As DataSet = New DataSet ... Dim myCredCache As CredentialCache = New CredentialCache ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Authentication problem for roles based
    ... the server passes these credentials to the AD controller, ... Even nesting AD impersonation with the following code doesn't seem to ... Dim impersonationContext As ... > settings are set to Integrated Windows Authentication only. ...
    (microsoft.public.dotnet.framework.aspnet)