Using XMLTextReader with Asp.net

G

Guest

I've ported some XML reading code from my WinForms app to my ASP.net app but
can't get it to work. Here's the code:

// Just testing locally for now
XmlReader reader = new XmlTextReader("http://localhost/TestApp/Menu.xml");
DataSet ds = new DataSet();
ds.ReadXml(reader, XmlReadMode.Auto);
reader.Close();


Yet I get the following error. I don't understand why it's "Unauthorized":

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.
 
G

Guest

Robert,
I believe you can't use a URL you have to use something like
XMLTextReader(HostingEnvironment.ApplicationPhysicalPath & "blah.xml")
 
G

Guest

Update: I later copied some code directly from MSDN and even that didn't
work, generating the same error. So I then went into the IIS Manager and
explicitly changed the security on the XML file to have Anonymous Access.
Suddenly everything worked!

My question now is: Why are XML files not given the same access as ASPX and
CS files? In other words, why did I have to go to this extra-ordinary step
to get my code to work?
 
G

Guest

Robert said:
Update: I later copied some code directly from MSDN and even that didn't
work, generating the same error. So I then went into the IIS Manager and
explicitly changed the security on the XML file to have Anonymous Access.
Suddenly everything worked!

My question now is: Why are XML files not given the same access as ASPX and
CS files? In other words, why did I have to go to this extra-ordinary step
to get my code to work?

How did you put the xml file in the web folder? If you copied it using
explorer you also copied the file permissions from the old location.
 
G

Guest

I tried it both ways - copying it from elsewhere and then creating a new one
from VStudio. It was the same problem both times. Not insurmountable but a
strange thing I thought. Now I'm going to have to get my [remote] client to
do the same.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top