What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 67065 |  Welcome, Guest!   Register  Login
 Home > Blogs > ASP.NET > Allow the Textbox control to accept Html text in Asp.net- An introduction to ValidateRequest Attribute in Asp.net ...
Niladri.Biswas

Allow the Textbox control to accept Html text in Asp.net- An introduction to ValidateRequest Attribute in Asp.net

 Blog author: Niladri.Biswas | Posted on: 5/26/2012 | Category: ASP.NET Blogs | Views: 2430 | Status: [Member] | Points: 75 | Alert Moderator     Download source file


Introduction

Paste the below line of text in a Asp.net Textbox control and click on the "Click Me" button

We will get an error page as under

Why it happens?

The web application has been prevented from processing unencoded HTML content submitted to the server.This is caused by the Request validation.It is a feature of ASP.NET (since version 1.1) which prevents the server from accepting un-encoded HTML content.It prevents script that may cause injection attacks.

When we run the application, we got the error

A potentially dangerous Request.Form value was detected from the client".(txtInput="<html><head><...").

What is the solution to this?

If we look minutely, the solution is given in the description

It offers two changes to happen in the web application

  1. Set the requestValidationMode attribute in the httpRuntime configuration section of the web.config file to requestValidationMode="2.0"

    e.g.

    				<system.web>
    <httpRuntime requestValidationMode="2.0" />
    </system.web>
  2. Once the above is done,we can then disable request validation by setting validateRequest="false" in the Page directive or in the <pages> configuration section

    e.g. At Page Level

    				<%@ 
    Page Language="C#"
    AutoEventWireup="true"
    CodeFile="TestPage.aspx.cs"
    Inherits="TestPage"
    ValidateRequest ="false"
    %>

    e.g. Globally at the <pages> configuration section

    				<system.web>
    <pages validateRequest="false" />
    </system.web>

Conclusion

Hope this short tutorial has helped us the use of ValidateRequest attribute and it's importance in the asp.net parlance.Thanks for reading




Best Regards,
Niladri Biswas
Found interesting? Add this to:


Experience:6 year(s)
Home page:http://www.dotnetfunda.com
Member since:Monday, October 25, 2010
Level:Diamond
Status: [Member]
Biography:Lead Engineer at HCL Technologies Ltd., having 6 years of experience in IT field.
I love to explore new technologies and love challenges and try to help others as much as possible not only by coding but also by all possible means.

 Responses

Akiii
Posted by: Akiii | Posted on: 5/27/2012 | Level: Bronze | Status: [Member] | Points: 15 | Alert Moderator 

Good and very useful article Sir, but putting validateRequest="false" is good ?
I mean to say your application will be vulnerable to attacks ?



Thanks and Regards
Akiii

>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 1:09:39 PM