Cấp bậc tác giả:

DOTNET

ValidateRequest=false không hoạt động trên .net framework 4.0 VS2010 ?

Được viết bởi QuangIT ngày 14/09/2012 lúc 08:08 AM
Bạn đang lập trình ASP.NET + .Net framework 4.0 trên bộ Visual Studio 2010 mới nhất của Microsoft ?
  • 0
  • 6213

ValidateRequest=false không hoạt động trên .net framework 4.0 VS2010 ?

Bạn đang lập trình ASP.NET + .Net framework 4.0 trên bộ Visual Studio 2010 mới nhất của Microsoft?

Bạn đã từng gặp lỗi A potentially dangerous Request.Form value was detected from the client từ Server trả về cho bạn khi bạn post dữ liệu không an toàn lên Server mặc dù bạn đã xử lý thuộc tính ValidateRequest = False trong cả @ Page directive và trong file web.config rồi?

<pages validateRequest="false"

<%@ Page ValidateRequest="false"

Error

Error: System.Web.HttpRequestValidationException
A potentially dangerous Request.Form value was detected from the client (ctl00$CC$txtAnswer=\"... World\r\n\r\nI am doing Testin...\")."} System.Web.HttpRequestValidationException
 
at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
   at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection)
   at System.Web.HttpRequest.get_Form()
   at System.Web.HttpRequest.get_HasForm()
   at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
   at System.Web.UI.Page.DeterminePostBackMode()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.displaypost_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a37c2f81\cfc4c927\App_Web_i2rujncl.9.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Để giải quyết vấn đề này chúng ta hãy vào file web.config và thêm 1 thẻ httpRuntime (nằm trong thẻ system.web) và set thuộc tính requestValidationMode="2.0"

<httpRuntime requestValidationMode="2.0" />

Và bạn có thể sử dụng thuộc tính ValidateRequest như bình thường.

Nguồn bài viết: Dngaz.com

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML