Fix Error : A potentially dangerous Request.Form value was detected asp.net

Thảo luận trong 'Lập trình web Asp.net' bắt đầu bởi admin, 15/3/17.

  1. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,900
    Đã được thích:
    1,199
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Khi thực hiện lưu, xóa sửa dữ liệu hoặc view dữ liệu trên asp.net, c# sẽ bị lỗi như sau: A potentially dangerous Request.Form value was detected from the client

    Chi tiết lỗi: Lỗi này do trong khung textbox, khung dữ liệu chứa mã html mà web cho là có nguy cơ gây nguy hiểm cho web, nên web chặn lại mỗi khi bạn request dữ liệu.

    Cách sử lỗi: chuyển requestValidationMode thành 2.0 để vượt qua lỗi này bằng cách
    • Khai bào vào trong web.config thêm đoạn code <httpRuntime requestValidationMode="2.0" /> và <pages validateRequest="false" /> trong thẻ <system.web> như dưới.
    • Lưu lại là xong.
    Mã:
    <configuration>
    ...
          <location path="MyFolder/.aspx">
          <system.web>
          <pages validateRequest="false" />
          <httpRuntime requestValidationMode="2.0" />
          </system.web>
          </location>
    ...
    </configuration>
    
    Chi tiết lỗi:
    Mã:
    Server Error in '/' Application.
    A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$txtDescription="...n da mịn m&#224;ng, căng b&#24...").
    Description: ASP.NET has detected data in the request that is potentially dangerous because it might include HTML markup or script. The data might represent an attempt to compromise the security of your application, such as a cross-site scripting attack. If this type of input is appropriate in your application, you can include code in a web page to explicitly allow it. For more information, see http://go.microsoft.com/fwlink/?LinkID=212874.
    Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$txtDescription="...n da mịn m&#224;ng, căng b&#24...").
    Source Error:
    [No relevant source lines]
    Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\1fbe6c70\38f3f5c8\App_Web_getautolinknews.aspx.be00b3d8.xiiij_ai.0.cs    Line: 0
    Stack Trace:
    [HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$txtDescription="...n da mịn m&#224;ng, căng b&#24...").]
       System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) +9777772
       System.Web.HttpRequest.ValidateHttpValueCollection(HttpValueCollection collection, RequestValidationSource requestCollection) +194
       System.Web.HttpRequest.get_Form() +50
       System.Web.HttpRequest.get_HasForm() +9778063
       System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +95
       System.Web.UI.Page.DeterminePostBackMode() +69
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6605
       System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +279
       System.Web.UI.Page.ProcessRequest() +72
       System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +22
       System.Web.UI.Page.ProcessRequest(HttpContext context) +58
       ASP.admincp_getautolinknews_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\1fbe6c70\38f3f5c8\App_Web_getautolinknews.aspx.be00b3d8.xiiij_ai.0.cs:0
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +188
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0 
    A-potentially-dangerous-Request-Form-value-was-detected-from-the-client.jpg
     
    Cảm ơn đã xem bài:

    Fix Error : A potentially dangerous Request.Form value was detected asp.net