ReadXml (DataSet) and WebException (401)

M

Marcos Martínez

I am trying to generate and to consume a file RSS dinamicamente. I generate
it correctly, if I call from the explorer (http://localhost/Prueba/rss.aspx)
or an application client RSS Bandit, for example, everything works
costraight.
But if I want to load "http://localhost/Prueba/rss.aspx" in a pagina
(http://localhost/Prueba/Lector.aspx) in metodo Page_Load:
XmlTextReader reader = null;
try
{
//Get the XML data
reader = new XmlTextReader(http://localhost/Prueba/rss.aspx);

// return a new DataSet
DataSet ds = new DataSet();
ds.ReadXml(reader);
}
catch
{
throw;
}
finally
{
if(reader!=null)
reader.Close();
}
It gives a WebException - "Error in the remote server: (401) nonauthorized
"and I do not understand because.
That it happens? Because can be read from other applications and no in the
same Web site?
A greeting and thanks.
Marcos
***************************************************************************
Estoy intentando generar y consumir dinamicamente un archivo RSS.Lo genero
correctamente, si lo llamo desde el explorador
(http://localhost/Prueba/rss.aspx) o una aplicación cliente RSS Bandit, por
ejemplo, todo funciona corectamente.
Pero si quiero cargar "http://localhost/Prueba/rss.aspx" en una pagina
(http://localhost/Prueba/Lector.aspx) en el metodo Page_Load:
XmlTextReader reader = null;
try
{
//Get the XML data
reader = new XmlTextReader(http://localhost/Prueba/rss.aspx);

// return a new DataSet
DataSet ds = new DataSet();
ds.ReadXml(reader);
}
catch
{
throw;
}
finally
{
if(reader!=null)
reader.Close();
}
Da un WebException - "error en el servidor alejado: (401) nonauthorized "y
no entiendo porque.
¿Que sucede? ¿Porque puede ser leído en otros usos y no en el mismo sitio
del Web?
Un saludo y gracias.
Marcos
 
P

Paul Glavich [MVP ASP.NET]

You need to use a HttpWebRequest something like (and this may not be 100%
correct):

HttpWebRequest rqst =
(HttpWebRequest)WebRequest.Create(http://localhost/Prueba/rss.aspx);
rqst.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse rsp = (HttpWebResponse)request.GetResponse ();
XmlTextReader rdr = new XmlTextReader(rsp.GetResponseStream());
 

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

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top