Access remote xml file using Credentials

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

  1. #1

    Default Access remote xml file using Credentials

    Hi

    I'm trying to access an xml document outside my site root to do some
    manipulation and I'm getting an error (on the while statement):

    The remote server returned an error: (401) Unauthorized.

    I guess this is because I don't have permissions on the file but I've been
    trying to set credentials before the file access. Can any one see what I'm
    doing wrong - Heres my code:
    ------------------------------------
    WebClient oWebClient = new WebClient();
    oWebClient.Credentials = CredentialCache.DefaultCredentials;

    string sResource = docRecord.Filepath + docRecord.Filename;
    Stream oStream = oWebClient.OpenRead(sResource);

    StreamReader oSR = new StreamReader(oStream);

    // create an instance of the XmlDocument object
    XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());

    oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    while(oXmlRdr.Read()) {
    // ... xml manipulation
    }

    // close the object and free up memory
    oXmlRdr.Close();
    oStream.Close();
    -----------------------------------
    and corresponding web.config entry:

    <authentication mode = "Forms">
    <forms>
    <credentials passwordFormat = "Clear">
    <user name ="ianb" password = "******"/>
    </credentials>
    </forms>
    </authentication>
    <authorization>
    <deny users = "?"/>
    </authorization>

    ===============================
    I have also tried the following and got the same result:
    WebClient oWebClient = new WebClient();
    NetworkCredential oCred = new NetworkCredential("ianb", "******");
    oWebClient.Credentials = oCred;
    String strURL = "http://validURL/XMLPage.xml";
    Stream oStream = oWebClient.OpenRead(strURL);
    StreamReader oSR = new StreamReader(oStream);

    XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;

    while(oXmlRdr.Read()) {
    // ... xml manipulation
    }

    // close the object and free up memory
    oXmlRdr.Close();
    oStream.Close();
    -------------------------------------
    I would prefer to use the web.config option. Can anyone help me with this

    Thanks

    Ian B
    Ianb Guest

  2. Similar Questions and Discussions

    1. How to get integrated credentials from anonymous access
      I want to allow both anonymous and integrated access to a web service simultaneously. That is, if the calling user can be authenticated on the...
    2. Access Denied with Custom Credentials
      Hi all, I'm exploring how to make authentication works with WebService. I've setup the WebService with no anonymous access and using Integrated...
    3. Web Service Credentials - Access Denied
      I am having problems passing the credentials from the current user to the Web Service. THANK YOU in advance for any help!! Web Service and Web...
    4. remote file access fails
      Context: Running Windows 2003 Server on an intranet. A web is configured with an anonymous access account that is a domain account that has...
    5. Remote Fax/Credentials
      I am trying to use one fax modem on a networked computer in Windows XP. The help instructs to set up the fax printer that is on the server as a...
  3. #2

    Default Access remote xml file using Credentials

    Hi

    I'm trying to access an xml document outside my site root to do some
    manipulation and I'm getting an error (on the while statement):

    The remote server returned an error: (401) Unauthorized.

    I guess this is because I don't have permissions on the file but I've been
    trying to set credentials before the file access. Can any one see what I'm
    doing wrong - Heres my code:
    ------------------------------------
    WebClient oWebClient = new WebClient();
    oWebClient.Credentials = CredentialCache.DefaultCredentials;

    string sResource = docRecord.Filepath + docRecord.Filename;
    Stream oStream = oWebClient.OpenRead(sResource);

    StreamReader oSR = new StreamReader(oStream);

    // create an instance of the XmlDocument object
    XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());

    oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    while(oXmlRdr.Read()) {
    // ... xml manipulation
    }

    // close the object and free up memory
    oXmlRdr.Close();
    oStream.Close();
    -----------------------------------
    and corresponding web.config entry:

    <authentication mode = "Forms">
    <forms>
    <credentials passwordFormat = "Clear">
    <user name ="ianb" password = "******"/>
    </credentials>
    </forms>
    </authentication>
    <authorization>
    <deny users = "?"/>
    </authorization>

    ===============================
    I have also tried the following and got the same result:
    WebClient oWebClient = new WebClient();
    NetworkCredential oCred = new NetworkCredential("ianb", "******");
    oWebClient.Credentials = oCred;
    String strURL = "http://validURL/XMLPage.xml";
    Stream oStream = oWebClient.OpenRead(strURL);
    StreamReader oSR = new StreamReader(oStream);

    XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;

    while(oXmlRdr.Read()) {
    // ... xml manipulation
    }

    // close the object and free up memory
    oXmlRdr.Close();
    oStream.Close();
    -------------------------------------
    I would prefer to use the web.config option. Can anyone help me with this

    Thanks

    Ian B
    Ianb Guest

  4. #3

    Default Access remote xml file using Credentials

    Hi

    I'm trying to access an xml document outside my site root to do some
    manipulation and I'm getting an error (on the while statement):

    The remote server returned an error: (401) Unauthorized.

    I guess this is because I don't have permissions on the file but I've been
    trying to set credentials before the file access. Can any one see what I'm
    doing wrong - Heres my code:
    ------------------------------------
    WebClient oWebClient = new WebClient();
    oWebClient.Credentials = CredentialCache.DefaultCredentials;

    string sResource = docRecord.Filepath + docRecord.Filename;
    Stream oStream = oWebClient.OpenRead(sResource);

    StreamReader oSR = new StreamReader(oStream);

    // create an instance of the XmlDocument object
    XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());

    oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    while(oXmlRdr.Read()) {
    // ... xml manipulation
    }

    // close the object and free up memory
    oXmlRdr.Close();
    oStream.Close();
    -----------------------------------
    and corresponding web.config entry:

    <authentication mode = "Forms">
    <forms>
    <credentials passwordFormat = "Clear">
    <user name ="ianb" password = "******"/>
    </credentials>
    </forms>
    </authentication>
    <authorization>
    <deny users = "?"/>
    </authorization>

    ===============================
    I have also tried the following and got the same result:
    WebClient oWebClient = new WebClient();
    NetworkCredential oCred = new NetworkCredential("ianb", "******");
    oWebClient.Credentials = oCred;
    String strURL = "http://validURL/XMLPage.xml";
    Stream oStream = oWebClient.OpenRead(strURL);
    StreamReader oSR = new StreamReader(oStream);

    XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;

    while(oXmlRdr.Read()) {
    // ... xml manipulation
    }

    // close the object and free up memory
    oXmlRdr.Close();
    oStream.Close();
    -------------------------------------
    I would prefer to use the web.config option. Can anyone help me with this

    Thanks

    Ian B
    Ianb Guest

  5. #4

    Default Re: Access remote xml file using Credentials

    Did you try supplying explicit credentials in the Credentials property
    instead of DefaultCredentials?

    Joe K.

    "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    news:0F163CF2-74C9-4DBC-BD5D-6ED6B1772014@microsoft.com...
    > Hi
    >
    > I'm trying to access an xml document outside my site root to do some
    > manipulation and I'm getting an error (on the while statement):
    >
    > The remote server returned an error: (401) Unauthorized.
    >
    > I guess this is because I don't have permissions on the file but I've been
    > trying to set credentials before the file access. Can any one see what I'm
    > doing wrong - Heres my code:
    > ------------------------------------
    > WebClient oWebClient = new WebClient();
    > oWebClient.Credentials = CredentialCache.DefaultCredentials;
    >
    > string sResource = docRecord.Filepath + docRecord.Filename;
    > Stream oStream = oWebClient.OpenRead(sResource);
    >
    > StreamReader oSR = new StreamReader(oStream);
    >
    > // create an instance of the XmlDocument object
    > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    >
    > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    > while(oXmlRdr.Read()) {
    > // ... xml manipulation
    > }
    >
    > // close the object and free up memory
    > oXmlRdr.Close();
    > oStream.Close();
    > -----------------------------------
    > and corresponding web.config entry:
    >
    > <authentication mode = "Forms">
    > <forms>
    > <credentials passwordFormat = "Clear">
    > <user name ="ianb" password = "******"/>
    > </credentials>
    > </forms>
    > </authentication>
    > <authorization>
    > <deny users = "?"/>
    > </authorization>
    >
    > ===============================
    > I have also tried the following and got the same result:
    > WebClient oWebClient = new WebClient();
    > NetworkCredential oCred = new NetworkCredential("ianb", "******");
    > oWebClient.Credentials = oCred;
    > String strURL = "http://validURL/XMLPage.xml";
    > Stream oStream = oWebClient.OpenRead(strURL);
    > StreamReader oSR = new StreamReader(oStream);
    >
    > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    >
    > while(oXmlRdr.Read()) {
    > // ... xml manipulation
    > }
    >
    > // close the object and free up memory
    > oXmlRdr.Close();
    > oStream.Close();
    > -------------------------------------
    > I would prefer to use the web.config option. Can anyone help me with this
    >
    > Thanks
    >
    > Ian B

    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: Access remote xml file using Credentials

    Hi Joe

    Only in the form I've shown you in the second coding attempt... ie:
    NetworkCredential oCred = new NetworkCredential("ianb", "******");
    oWebClient.Credentials = oCred;

    is there another way to do this?

    Ian

    "Joe Kaplan (MVP - ADSI)" wrote:
    > Did you try supplying explicit credentials in the Credentials property
    > instead of DefaultCredentials?
    >
    > Joe K.
    >
    > "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    > news:0F163CF2-74C9-4DBC-BD5D-6ED6B1772014@microsoft.com...
    > > Hi
    > >
    > > I'm trying to access an xml document outside my site root to do some
    > > manipulation and I'm getting an error (on the while statement):
    > >
    > > The remote server returned an error: (401) Unauthorized.
    > >
    > > I guess this is because I don't have permissions on the file but I've been
    > > trying to set credentials before the file access. Can any one see what I'm
    > > doing wrong - Heres my code:
    > > ------------------------------------
    > > WebClient oWebClient = new WebClient();
    > > oWebClient.Credentials = CredentialCache.DefaultCredentials;
    > >
    > > string sResource = docRecord.Filepath + docRecord.Filename;
    > > Stream oStream = oWebClient.OpenRead(sResource);
    > >
    > > StreamReader oSR = new StreamReader(oStream);
    > >
    > > // create an instance of the XmlDocument object
    > > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    > >
    > > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    > > while(oXmlRdr.Read()) {
    > > // ... xml manipulation
    > > }
    > >
    > > // close the object and free up memory
    > > oXmlRdr.Close();
    > > oStream.Close();
    > > -----------------------------------
    > > and corresponding web.config entry:
    > >
    > > <authentication mode = "Forms">
    > > <forms>
    > > <credentials passwordFormat = "Clear">
    > > <user name ="ianb" password = "******"/>
    > > </credentials>
    > > </forms>
    > > </authentication>
    > > <authorization>
    > > <deny users = "?"/>
    > > </authorization>
    > >
    > > ===============================
    > > I have also tried the following and got the same result:
    > > WebClient oWebClient = new WebClient();
    > > NetworkCredential oCred = new NetworkCredential("ianb", "******");
    > > oWebClient.Credentials = oCred;
    > > String strURL = "http://validURL/XMLPage.xml";
    > > Stream oStream = oWebClient.OpenRead(strURL);
    > > StreamReader oSR = new StreamReader(oStream);
    > >
    > > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    > > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    > >
    > > while(oXmlRdr.Read()) {
    > > // ... xml manipulation
    > > }
    > >
    > > // close the object and free up memory
    > > oXmlRdr.Close();
    > > oStream.Close();
    > > -------------------------------------
    > > I would prefer to use the web.config option. Can anyone help me with this
    > >
    > > Thanks
    > >
    > > Ian B
    >
    >
    >
    Ianb Guest

  7. #6

    Default Re: Access remote xml file using Credentials

    Is the other site using Forms authentication as well? If so, you are going
    to have to do some extra work to authenticate with it.

    You will either need to screen scrape the logon screen to do the correct
    Form post to get the logon cookie, or you will need to configure things so
    that you can pass your ASP.NET forms authentication cookie to the other site
    directly.

    All this stuff having to do with DefaultCredentials and such only works with
    Windows authentication.

    Joe K.

    "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    news:4031C246-928C-4932-8805-137D98986E0A@microsoft.com...
    > Hi Joe
    >
    > Only in the form I've shown you in the second coding attempt... ie:
    > NetworkCredential oCred = new NetworkCredential("ianb", "******");
    > oWebClient.Credentials = oCred;
    >
    > is there another way to do this?
    >
    > Ian
    >
    > "Joe Kaplan (MVP - ADSI)" wrote:
    >
    >> Did you try supplying explicit credentials in the Credentials property
    >> instead of DefaultCredentials?
    >>
    >> Joe K.
    >>
    >> "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    >> news:0F163CF2-74C9-4DBC-BD5D-6ED6B1772014@microsoft.com...
    >> > Hi
    >> >
    >> > I'm trying to access an xml document outside my site root to do some
    >> > manipulation and I'm getting an error (on the while statement):
    >> >
    >> > The remote server returned an error: (401) Unauthorized.
    >> >
    >> > I guess this is because I don't have permissions on the file but I've
    >> > been
    >> > trying to set credentials before the file access. Can any one see what
    >> > I'm
    >> > doing wrong - Heres my code:
    >> > ------------------------------------
    >> > WebClient oWebClient = new WebClient();
    >> > oWebClient.Credentials = CredentialCache.DefaultCredentials;
    >> >
    >> > string sResource = docRecord.Filepath + docRecord.Filename;
    >> > Stream oStream = oWebClient.OpenRead(sResource);
    >> >
    >> > StreamReader oSR = new StreamReader(oStream);
    >> >
    >> > // create an instance of the XmlDocument object
    >> > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    >> >
    >> > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    >> > while(oXmlRdr.Read()) {
    >> > // ... xml manipulation
    >> > }
    >> >
    >> > // close the object and free up memory
    >> > oXmlRdr.Close();
    >> > oStream.Close();
    >> > -----------------------------------
    >> > and corresponding web.config entry:
    >> >
    >> > <authentication mode = "Forms">
    >> > <forms>
    >> > <credentials passwordFormat = "Clear">
    >> > <user name ="ianb" password = "******"/>
    >> > </credentials>
    >> > </forms>
    >> > </authentication>
    >> > <authorization>
    >> > <deny users = "?"/>
    >> > </authorization>
    >> >
    >> > ===============================
    >> > I have also tried the following and got the same result:
    >> > WebClient oWebClient = new WebClient();
    >> > NetworkCredential oCred = new NetworkCredential("ianb", "******");
    >> > oWebClient.Credentials = oCred;
    >> > String strURL = "http://validURL/XMLPage.xml";
    >> > Stream oStream = oWebClient.OpenRead(strURL);
    >> > StreamReader oSR = new StreamReader(oStream);
    >> >
    >> > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    >> > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    >> >
    >> > while(oXmlRdr.Read()) {
    >> > // ... xml manipulation
    >> > }
    >> >
    >> > // close the object and free up memory
    >> > oXmlRdr.Close();
    >> > oStream.Close();
    >> > -------------------------------------
    >> > I would prefer to use the web.config option. Can anyone help me with
    >> > this
    >> >
    >> > Thanks
    >> >
    >> > Ian B
    >>
    >>
    >>

    Joe Kaplan \(MVP - ADSI\) Guest

  8. #7

    Default Re: Access remote xml file using Credentials

    Hi Joe

    To clarify, I am trying to access a Word XML format document in a sharepoint
    library from a custom ASPX file in an excluded directory under the same
    sharepoint site.

    So I guess the sharepoint site is using the same web.config hense yes the
    other site is using forms authentication.

    The site uses windows authentication so (from what you are saying) I am
    heading the right way but I have some errors in my code.

    Ian

    "Joe Kaplan (MVP - ADSI)" wrote:
    > Is the other site using Forms authentication as well? If so, you are going
    > to have to do some extra work to authenticate with it.
    >
    > You will either need to screen scrape the logon screen to do the correct
    > Form post to get the logon cookie, or you will need to configure things so
    > that you can pass your ASP.NET forms authentication cookie to the other site
    > directly.
    >
    > All this stuff having to do with DefaultCredentials and such only works with
    > Windows authentication.
    >
    > Joe K.
    >
    > "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    > news:4031C246-928C-4932-8805-137D98986E0A@microsoft.com...
    > > Hi Joe
    > >
    > > Only in the form I've shown you in the second coding attempt... ie:
    > > NetworkCredential oCred = new NetworkCredential("ianb", "******");
    > > oWebClient.Credentials = oCred;
    > >
    > > is there another way to do this?
    > >
    > > Ian
    > >
    > > "Joe Kaplan (MVP - ADSI)" wrote:
    > >
    > >> Did you try supplying explicit credentials in the Credentials property
    > >> instead of DefaultCredentials?
    > >>
    > >> Joe K.
    > >>
    > >> "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    > >> news:0F163CF2-74C9-4DBC-BD5D-6ED6B1772014@microsoft.com...
    > >> > Hi
    > >> >
    > >> > I'm trying to access an xml document outside my site root to do some
    > >> > manipulation and I'm getting an error (on the while statement):
    > >> >
    > >> > The remote server returned an error: (401) Unauthorized.
    > >> >
    > >> > I guess this is because I don't have permissions on the file but I've
    > >> > been
    > >> > trying to set credentials before the file access. Can any one see what
    > >> > I'm
    > >> > doing wrong - Heres my code:
    > >> > ------------------------------------
    > >> > WebClient oWebClient = new WebClient();
    > >> > oWebClient.Credentials = CredentialCache.DefaultCredentials;
    > >> >
    > >> > string sResource = docRecord.Filepath + docRecord.Filename;
    > >> > Stream oStream = oWebClient.OpenRead(sResource);
    > >> >
    > >> > StreamReader oSR = new StreamReader(oStream);
    > >> >
    > >> > // create an instance of the XmlDocument object
    > >> > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    > >> >
    > >> > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    > >> > while(oXmlRdr.Read()) {
    > >> > // ... xml manipulation
    > >> > }
    > >> >
    > >> > // close the object and free up memory
    > >> > oXmlRdr.Close();
    > >> > oStream.Close();
    > >> > -----------------------------------
    > >> > and corresponding web.config entry:
    > >> >
    > >> > <authentication mode = "Forms">
    > >> > <forms>
    > >> > <credentials passwordFormat = "Clear">
    > >> > <user name ="ianb" password = "******"/>
    > >> > </credentials>
    > >> > </forms>
    > >> > </authentication>
    > >> > <authorization>
    > >> > <deny users = "?"/>
    > >> > </authorization>
    > >> >
    > >> > ===============================
    > >> > I have also tried the following and got the same result:
    > >> > WebClient oWebClient = new WebClient();
    > >> > NetworkCredential oCred = new NetworkCredential("ianb", "******");
    > >> > oWebClient.Credentials = oCred;
    > >> > String strURL = "http://validURL/XMLPage.xml";
    > >> > Stream oStream = oWebClient.OpenRead(strURL);
    > >> > StreamReader oSR = new StreamReader(oStream);
    > >> >
    > >> > XmlTextReader oXmlRdr = new XmlTextReader(oSR.ReadToEnd());
    > >> > oXmlRdr.WhitespaceHandling = WhitespaceHandling.None;
    > >> >
    > >> > while(oXmlRdr.Read()) {
    > >> > // ... xml manipulation
    > >> > }
    > >> >
    > >> > // close the object and free up memory
    > >> > oXmlRdr.Close();
    > >> > oStream.Close();
    > >> > -------------------------------------
    > >> > I would prefer to use the web.config option. Can anyone help me with
    > >> > this
    > >> >
    > >> > Thanks
    > >> >
    > >> > Ian B
    > >>
    > >>
    > >>
    >
    >
    >
    Ianb Guest

  9. #8

    Default Re: Access remote xml file using Credentials

    Ok,

    If the target file is on a SharePoint site, then it is almost certainly
    using Windows authentication, not Forms authentication. You should be able
    to tell by whether you are sent to a custom logon form when you first point
    your browser to it or whether the browser prompts you or logs you on
    automatically.

    If it is Windows authentication (which it should be), then you should be
    able to get the NetworkCredential approach to work. You might try adding a
    valid domain to your constructor:

    NetworkCredential oCred = new NetworkCredential("ianb", "******",
    "iansdomain");

    If that doesn't work, please provide more details and we'll see what we can
    do.

    Joe K.
    "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    news:64AAB084-2574-48C9-9876-A41723760BB6@microsoft.com...
    > Hi Joe
    >
    > To clarify, I am trying to access a Word XML format document in a
    > sharepoint
    > library from a custom ASPX file in an excluded directory under the same
    > sharepoint site.
    >
    > So I guess the sharepoint site is using the same web.config hense yes the
    > other site is using forms authentication.
    >
    > The site uses windows authentication so (from what you are saying) I am
    > heading the right way but I have some errors in my code.
    >
    > Ian
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  10. #9

    Default Re: Access remote xml file using Credentials

    Good thinking but I'm still not winning. I put some exception trapping in and
    here is the response:
    System.Net.WebException: The remote server returned an error: (401)
    Unauthorized. at System.Net.HttpWebRequest.CheckFinalStatus() at
    System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult) at
    System.Net.HttpWebRequest.GetResponse() at
    System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials
    credentials) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
    credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String
    role, Type ofObjectToReturn) at System.Xml.XmlTextReader.CreateScanner() at
    System.Xml.XmlTextReader.Init() at System.Xml.XmlTextReader.Read() at
    ASP.DocumentBuilder_aspx.Page_Load() in
    D:\Inetpub\wwwroot\WorkSQE\scripts\DocumentBuilder .aspx:line 58


    Ian

    "Joe Kaplan (MVP - ADSI)" wrote:
    > Ok,
    >
    > If the target file is on a SharePoint site, then it is almost certainly
    > using Windows authentication, not Forms authentication. You should be able
    > to tell by whether you are sent to a custom logon form when you first point
    > your browser to it or whether the browser prompts you or logs you on
    > automatically.
    >
    > If it is Windows authentication (which it should be), then you should be
    > able to get the NetworkCredential approach to work. You might try adding a
    > valid domain to your constructor:
    >
    > NetworkCredential oCred = new NetworkCredential("ianb", "******",
    > "iansdomain");
    >
    > If that doesn't work, please provide more details and we'll see what we can
    > do.
    >
    > Joe K.
    > "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    > news:64AAB084-2574-48C9-9876-A41723760BB6@microsoft.com...
    > > Hi Joe
    > >
    > > To clarify, I am trying to access a Word XML format document in a
    > > sharepoint
    > > library from a custom ASPX file in an excluded directory under the same
    > > sharepoint site.
    > >
    > > So I guess the sharepoint site is using the same web.config hense yes the
    > > other site is using forms authentication.
    > >
    > > The site uses windows authentication so (from what you are saying) I am
    > > heading the right way but I have some errors in my code.
    > >
    > > Ian
    > >
    >
    >
    >
    Ianb Guest

  11. #10

    Default Re: Access remote xml file using Credentials


    The trick to this is going to be figuring out what credentials you need to
    access the SharePoint server and then pass those in the correct format. I
    suggest setting IE to always prompt for Windows Integrated authentication
    and then make sure you pass the same stuff in your WebRequest via the
    Credentials property. WebRequest is really just doing what the browser is
    doing, so your goal is to make sure you can simulate that properly.

    I'm not sure what else I can tell you without having more details about how
    the authentication with SharePoint is working.

    Joe K.

    "Ianb" <Ianb@discussions.microsoft.com> wrote in message
    news:91561217-F325-4303-83C7-03E8D71BC590@microsoft.com...
    > Good thinking but I'm still not winning. I put some exception trapping in
    > and
    > here is the response:
    > System.Net.WebException: The remote server returned an error: (401)
    > Unauthorized. at System.Net.HttpWebRequest.CheckFinalStatus() at
    > System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult) at
    > System.Net.HttpWebRequest.GetResponse() at
    > System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials
    > credentials) at System.Xml.XmlDownloadManager.GetStream(Uri uri,
    > ICredentials
    > credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri,
    > String
    > role, Type ofObjectToReturn) at System.Xml.XmlTextReader.CreateScanner()
    > at
    > System.Xml.XmlTextReader.Init() at System.Xml.XmlTextReader.Read() at
    > ASP.DocumentBuilder_aspx.Page_Load() in
    > D:\Inetpub\wwwroot\WorkSQE\scripts\DocumentBuilder .aspx:line 58
    >
    >
    > Ian

    Joe Kaplan \(MVP - ADSI\) 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