Asp.net

將 html 標記從 jquery 發布呼叫發送到 asp.net 頁面時,從客戶端檢測到潛在危險的 Request.QueryString 值

  • October 7, 2010

我正在使用 jQuery 對 ASP.NET 頁面進行 ajax 呼叫,該頁面充當我的 ajax 伺服器頁面,以將我發送給它的數據保存在查詢字元串中。在 ASP.NET 頁面中,當我嘗試讀取查詢字元串時出現此錯誤:

A potentially dangerous Request.QueryString value was detected from the client...

我已經 ValidateRequest="false"在我的頁面中設置了。不想為所有頁面設置它。在頁面級別而不是配置級別也是如此:

 var content = "<h3>Sample header</h3><p>sample para</p>"
 content = encodeURIComponent(content);
 var url = "../Lib/ajaxhandler.aspx?mode=savecontent&page=home&ltxt=" + content;

    $.post(url, function (data) { 
      //check return value and do something
  });

在我的 asp.net 頁面中:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ajaxhandler.aspx.cs" ValidateRequest="false" Inherits="MyProject.Lib.ajaxhandler" %>

但是當我發送純文字而不是 html 標記時,它工作正常。

如果這是 ASP.NET 4 那麼ValidateRequest. 有關更多資訊,請參閱此 StackOverflow 問題requestValidationMode

引用自:https://stackoverflow.com/questions/3885697