xml.save vs storing xml in a session variable...if the latter, how?


I am retrieving an xml from a URL and then I need to make it accesible to different pages within my asp.net application.
I have come accross two potential ways of doing this. One is by storing the file in disk using xml.save.
The other is by storing the xml in a session variable.

The first option I have figured out how to do it. But I am not sure if that option is better than the second one. As for the second one, I have managed to store the xml in a session variable,
XmlDocument xmlDoc = new XmlDocument();
Session["xml"] = xmlDoc.InnerXml;

but cannot read it in the receiving page, because
xmlDoc.InnerXml = Session["xml"];
is giving error.

Thanks in advance for making this site a value added resource.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

cascader_grConnect With a Mentor Commented:
XmlDocument xmlDoc = new XmlDocument();
Session["xml"] = xmlDoc.OuterXml;

//And then...
robespierre_2010Author Commented:


this does not work because


is empty in the receiving page.

Just a thought that I had whilst reading your question, does the entire XML file actually need to be stored in each session?

Perhaps just the URL needs to be stored (preferably in relative form for security reasons). The XML file could then simply be reloaded by URL each time a request is made. Unless, of course, the XML is dynamically tailored for the current session/user.

With regards to your empty value problem, is the second page being loaded in a separate session, I have experienced this when using multiple web browser instances?
robespierre_2010Author Commented:
the problem with calling the url each time is that the xml obtained may vary as the underlying data change with time. so it is necessary to stor the xml.

the second page is loaded in the same session(and same browser instance). there is a session variable that stores only a string and that is being passed correctly from one page to the other. but the xml isn't.

All Courses

From novice to tech pro — start learning today.