July 2005 - Posts

Avoid the HttpRequestValidationException Exception

To avoid the HttpRequestValidationException Exception  you' ll have to set the flag validateRequest in the page directive .

See below:

<%@ Page language="c#" validateRequest="false" Codebehind="TestForm.aspx.cs" AutoEventWireup="false" Inherits="TestForm" %>

Ofcourse there is a downside. When you disable the validation you will have to prevent script injection yourself. Just don't forget to encode your html code and querystrings.

This can be done by using the following code snippet:

For HtmlCode

string safeFormFieldName = Server.HtmlEncode(formFieldName);

For QueryString

string safeQuery = Server.UrlEncode(fulfillmentFormName);

The .NET framework will escape the illegal characters like < ' >. It will replace the character < with &lt;

The browser will correctly interpret the &lt; and decode the character to <.

Posted by Chi Wai Man | 1 comment(s)
Filed under:

My First post

Well I finally got my own Blog. This is my first post to say hello:)
Posted by Chi Wai Man | with no comments