System.Web.ConfigurationSystem.Web.dllPagesSectiontrue(.NET 2.0 新增)驗證用戶輸入是否包含危險字元(<script> 等),偵測到即拋出 HttpRequestValidationException,顯示黃色錯誤頁(YSOD)。
validateRequest,自行過濾/編碼危險字元(易漏網)。validateRequest=true。protected void Page_Error(object sender, EventArgs e)
{
var ex = Server.GetLastError();
if (ex is HttpRequestValidationException)
{
Response.Write("您輸入的字元中含有非法字元!");
Server.ClearError();
}
}
替換嚇人的 YSOD,提升使用者體驗。