Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Access remote xml file using Credentials

Reply
Thread Tools

Access remote xml file using Credentials

 
 
Ianb
Guest
Posts: n/a
 
      01-20-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using credentials to control access to public methods: good or badidea? Olli Plough Java 2 12-01-2007 05:32 PM
"The credentials supplied conflict with an existing set of credentials" -=rjh=- NZ Computing 2 07-15-2006 11:09 PM
Access remote xml file using Credentials Ianb ASP .Net Security 7 01-21-2005 01:35 AM
Remote Assistance fails to connect, remote remote host name could not be resolved Peter Sale Wireless Networking 1 12-11-2004 09:09 PM
Re: Pass Basic Auth. credentials to remote site? Craig Deelsnyder ASP .Net 2 07-21-2004 06:00 PM



Advertisments
 



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