ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

C

Colin Bowern

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top