ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

    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(IAsyncRes ult 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(HtmlTextWrite r 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


    Colin Bowern Guest

  2. Similar Questions and Discussions

    1. DefaultCredentials problem?
      Hi All, this is the scenario: - "Hello World" web service on Machine A - winform client on Machine B - asp.net webform client on Machine B ...
    2. 401 Unauthorized when using DefaultCredentials
      Hi all I hope this is the right newsgroup. I'm having a hard time making a web request from an authenticated process. Here's the scenario Managed...
    3. Get DefaultCredentials of one web app into another?
      We have a web app which links to another ASP.NET web application (namely the Microsoft CRM). Our app is launched in a new browser window from a link...
    4. HttpWebRequest, impersonation and DefaultCredentials problem.
      I'm trying to create a HttpWebRequest object that uses the current logged in user's credentials. It's currently setup with: <identity...
    5. DefaultCredentials and WebClient
      I'm trying to make a call inside an ASP.NET web application to an external quasi-web service (aka FrontPage Server Extensions): Dim rpcClient As...
  3. #2

    Default Re: ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

    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(IAsyncRes ult 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(HtmlTextWrite r 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
    >
    >

    Colin Bowern Guest

  4. #3

    Default Re: ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

    Anyone have any thoughts on how to get the user credentials to pass through
    without manually creating a NetworkCredential object?

    Thanks!
    Colin

    "Colin Bowern" <colin.bowern@nospam.indimensions.com> wrote in message
    news:OLGkxoX0DHA.1764@TK2MSFTNGP10.phx.gbl...
    > 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(IAsyncRes ult 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(HtmlTextWrite r 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
    > >
    > >
    >
    >

    Colin Bowern Guest

  5. #4

    Default Re: ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials

    Colin
    Did you ever get this problem solved? I am having the same problem
    with my asp.net application.

    Does anyone know how i can check if impersonation is actually working?
    I have it set to true in the applications web.config file. I have read
    a couple of articles that say that you can pass around the logged in
    users credential, but I cannot get it to work.
    TIA
    Kenneth

    "Colin Bowern" <colin.bowern@nospam.indimensions.com> wrote in message news:<umy#Ves1DHA.2396@TK2MSFTNGP09.phx.gbl>...
    > Anyone have any thoughts on how to get the user credentials to pass through
    > without manually creating a NetworkCredential object?
    >
    > Thanks!
    > Colin
    >
    > "Colin Bowern" <colin.bowern@nospam.indimensions.com> wrote in message
    > news:OLGkxoX0DHA.1764@TK2MSFTNGP10.phx.gbl...
    > > 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(IAsyncRes ult 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(HtmlTextWrite r 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
    > > >
    > > >
    > >
    > >
    Kenneth Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139