Storing XML in Cookies and "dangerous Request.Cookies value" in ASP.Net

by demtron on Saturday, February 28, 2009 05:32 PM

By design, when attempting to store XML data in a cookie, the .Net Framework will raise the a HttpRequestValidationException because request validation is enabled according to Microsoft.  This is a good security mechanism to help avoid script submissions via HTTP.  Rather than turning off validation, one way to eliminate problem is to use HttpUtility.UrlEncode and HttpUtility.UrlDecode to replace suspicious characters with acceptable characters.  For example, to store an XML string to a cookie, one could use the following code:

HttpContext.Current.Response.Cookies.Set(New HttpCookie("Books", HttpUtility.UrlEncode(XMLstring)))
 


Converting .Net DataTable to an XML String

by demtron on Saturday, February 28, 2009 05:19 PM

Here is a snippet of code that will convert a VB.Net DataTable into a string of XML.

Dim SB As New StringBuilder
Dim SW As New IO.StringWriter(SB)
Items.WriteXml(SW, Data.XmlWriteMode.WriteSchema)

This code writes the contents and schema of the DataTable in to a StringBuilder by way of a StringWriter object.


Powered by BlogEngine.NET 1.5.1.18
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share

Calendar

<<  February 2009  >>
MoTuWeThFrSaSu
2627282930311
2345678
9101112131415
16171819202122
2324252627281
2345678

View posts in large calendar
Log in

Milwaukee SEO Company

Milwaukee Access Programmer/Developer

Milwaukee Website Designer and Developer



Marketing / SEO

Blog Directory
blogarama - the blog directory
TopOfBlogs
Milwaukee area SEO, SEM, ASP.Net