I
Ianb
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
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