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

<<  March 2024  >>
MoTuWeThFrSaSu
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

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