> For the complete documentation index, see [llms.txt](https://brianwu.gitbook.io/brian/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brianwu.gitbook.io/brian/asp.net-web-form/lve-guo-qing-qiu-yan-zheng.md).

# 略過請求驗證

## 略過請求驗證

參考網址(<https://msdn.microsoft.com/en-us/library/hh882339.aspx>)

由於ASP.NET的form會檢查使用者輸入的值，避免惡意的使用者輸入JS的指令，來鑽漏洞，此方法稱為XSS攻擊。

若要避開這個驗證，建議要手動檢查使用者傳入的值。

在此就不多談其他，僅記錄我的實作方法和遇到的問題。

## 放在Web.config內

這是我寫的部分

```
<configuration>
  <!--程式碼放在這個區塊-->
  <location path ="dirName/fileName.aspx">
    <system.web>
      <httpRuntime requestValidationMode ="2.0"/>
    </system.web>
  </location>
  <!--程式碼放在這個區塊-->
</configuration>
```

由於參考資料 "2.0" 的雙引號為 ＂(全形)，所以出錯 另外參考資料的結尾為 "\</ location>"，這會導致出錯，"/" 和後面的tag之間不可以有空格。

## 放在dirName/fileName.aspx 此檔案的部分

```
<%@ Page Language="C#" validateRequest ="false">
```

僅在後面增加 validateRequest ="false" 就好了

題外話:利用上述方法，使得該頁面的輸入格可以輸入html tag，僅使用""也沒問題，但是在裡面打字，不管是設變數、console.log()、document.write()等等，都會被Chrome給擋掉，用Firefox開則可以正常顯示。

輸入字串

```
"<div id="abc123" style="color:green">123</div><script>var a = document.getElementById("abc123"); console.log(a);document.write("Hello World<br>");</script>"
```

顯示結果

&#x20;![](/files/-LmbdtOVc7FTk6ZM7IgL)
