Using XMLTextReader with Asp.net

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Robert,
I believe you can't use a URL you have to use something like
XMLTextReader(HostingEnvironment.ApplicationPhysicalPath & "blah.xml")
 
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?
 
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.
 
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.
 
Back
Top