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)))
 


Comments

Comments are closed

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

Bookmark and Share

Calendar

<<  October 2024  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

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