วิธีการแก้ไขปัญหา A potentially dangerous Request.Form value was detected from the client ใน .NET
----------------------------------------------------------------------------
A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$dvContentDetails$txtLDetail="<p>
ข้อความ</p>
").
Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. To allow pages to override application request validation settings, set the requestValidationMode attribute in the httpRuntime configuration section to requestValidationMode="2.0". Example: <httpRuntime requestValidationMode="2.0" />. After setting this value, you can then disable request validation by setting validateRequest="false" in the Page directive or in the <pages> configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. For more information
----------------------------------------------------------------------------
ปัญหาลักษณะนี้ เกิดจากการส่งค่าผ่านฟอร์มด้วยแท็กพิเศษ เช่น HTML Code ใน .net มันจะแสดง error ขึ้นมา และสร้างความปวดหัวให้กับ Developer. ส่วนมากแล้วปัญหานี้มักเกิดกับการทำฟอร์มโดยใช้ Editor เช่น CKeditor เข้ามาช่วย วิธีแก้ไขปัญหานี้ มี 3 วิธีคับ1. กำหนด ValidateRequest="false" ไว้บนหัวเพจ ตัวอย่างเช่น
<%@ Page Title="" Language="C#" MasterPageFile="~/Backend/BackendMasterPage.master" AutoEventWireup="true" CodeFile="ManageContent.aspx.cs" Inherits="Backend_ManageContent" ValidateRequest="false" EnableEventValidation="false" %>
2. ไปแก้ไฟล์ config.js ของสคริปต์ตัว ckeditor ครับ แล้วเพิ่ม config.HtmlEncodeOutput = true; เข้าไป
// config.js
CKEDITOR.editorConfig = function(config) {
config.HtmlEncodeOutput = true;
};
3. กำหนด <httpRuntime requestValidationMode="2.0" /> ไว้ในไฟล์ web.config
สำหรับสองวิธีแรกคือวิธีพื้นๆที่สุด ส่วนวิธีที่ 3 สำหรับโปรเจคที่เป็น .net framework 4.0 ขึ้นไปครับ
แหล่งศึกษาเพิ่มเติม
http://greatfriends.biz/webboards/msg.asp?id=121548
http://greatfriends.biz/webboards/msg.asp?id=119975Tag : A potentially dangerous Request.Form,.NET, Ckeditor, วิธีแก้ไขปัญหา