Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display XML locally using asp.net C# 2

Status
Not open for further replies.

defconfyv

Programmer
Joined
Jul 7, 2005
Messages
3
Location
US
I have been having trouble doing something I always thought would be simple until I actually have to do it. I am basically wanting to read an RSS feed and display it locally so that flash can read it without having to cross domains. So I created an asp.net page and did the following in the page load:

XmlTextReader myX = new XmlTextReader("myX.Read();
string info = myX.ReadOuterXml();
Response.Write(info);

When I debug this, I notice that info had everything in it properly but I get this page is not available error in internet explorer when I try to browse this page. It just isnt working. Does anyone have a script that basically proxy's an RSS feed?
 
Well that makes sense if I want to grab an RSS feed and display the data from it. I actually already know how to do that. In turn I am trying to create a proxy of an RSS feed. In other words I want to grab all the XML from a URL and then redisplay it in my own window.

See flash cannot read an XML file across another domain unless I own the domain and put a policy file in the root directory allowing flash to access it. Sounds stupid but thats the rules set up by macromedia's flash player 7. So instead of rewriting my flash application, I thought it easier to actually use an asp.net page to copy the feed and redisplay it as a feed. Should be easy, right? I mean PHP can do this in 2 lines of code, though I prefer to accomplish the task in the .net environment.
 
In other words I want to grab all the XML from a URL and then redisplay it in my own window.
In that case it should be fairly simple. Have a look at the HttpWebRequest method.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Try this. There is probable a way to avoid going all the way to text (using the stream directly). That way Encoding.ASCII isn't such a magic number. The URL you provided hung on my computer even though I could see it in a browser.

//Get the feed
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(stream, Encoding.ASCII);
string responseString = reader.ReadToEnd();
reader.Close();

//Write the output
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "text/xml";
Response.AddHeader("Content-Disposition","inline;filename=Redirect.xml");
Response.Write(responseString);
Response.End();
 
Thanks stsuing that worked like a charm. I knew it couldn't be that complicated, though it does seem to be more complicated than the php equivalent. I am not going to argue with what works, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top