473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Using XMLTextReader with Asp.net

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 W.
Vancouver, BC
www.mwtech.com

Apr 30 '06 #1
4 1812
Robert,
I believe you can't use a URL you have to use something like
XMLTextReader(HostingEnvironment.ApplicationPhysic alPath & "blah.xml")

"Robert W." wrote:
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 W.
Vancouver, BC
www.mwtech.com

Apr 30 '06 #2
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 W.
Vancouver, BC
www.mwtech.com

"Robert W." wrote:
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 W.
Vancouver, BC
www.mwtech.com

Apr 30 '06 #3
Robert W. wrote:
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.
Apr 30 '06 #4
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.

--
Robert W.
Vancouver, BC
www.mwtech.com

"Göran Andersson" wrote:
Robert W. wrote:
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.

Apr 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob Rosen | last post by:
My message concerns a sample application that I took verbatim from the book titled "SAMS Teach Yourself Visual Basic.NET Web Programming in 21 days". It consists of a web page that takes the names...
3
by: Daniel | last post by:
Greetings. Just wondering if it is possible to use XmlTextReader to read off a html doc: e.g. XmlTextReader tr = new XmlTextReader ("http://localhost/test.xml"); where test.xml contains...
3
by: Russell Mangel | last post by:
Is it possible to use the using statement with XmlTextReader? I tryed to use it, but it gives me the error message: Cannot implicitly convert type 'System.Xml.XmlTextReader' to...
3
by: Pete | last post by:
I'm trying to read an XML document and write out a slightly modified version using the XmlTextWriter. I'm basically trying to copy all the nodes exactly as they are read and do some text...
2
by: Mitch | last post by:
I have some simple HTML I'm trying to read with the XMLTextReader. As in the MSDS examples, I set up a loop to read each XML node: while (reader.Read()) { switch (reader.NodeType) { case...
4
by: Rich Wallace | last post by:
Hi all, I have an XML document fed to me from a third party app: <?xml version="1.0" encoding="WINDOWS-1252" ?> <GatewayPlan xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
2
by: Yuriy | last post by:
Hi, any ideas how to read XML fragment from TextReader? XmlTextReader constructor accepts only Stream or string as source Do I miss something? thanks Yuriy
1
by: Jordan | last post by:
I have a unicode XML file that I am trying to read using the .NET XmlTextReader in C#. How do I read the unicode file? If I try to using the XmlTextReader.Read() method, it throws an exception. ...
16
by: danielbuus | last post by:
....or, to put it perhaps more communicative, something like this: Type someObjectsType = someObject.GetType(); someObjectsType newObject = new someObjectsType(); Is this possible? If so, how?...
3
by: apiringmvp | last post by:
All, So I am creating a function that gets a short blurb of html from a blog. I would like to retain all html formating and images. The code below works well, with the exception of one issue....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.