Webform1.aspx
has grid.Grid contains edit button。點擊編輯按鈕,用戶被重定向到webform2.aspx
頁面。查詢字符串ID傳遞給Webform2.aspx
。 Webform2.aspx
顯示該ID的所有數據。 Webform包含下拉列表,文本框和按鈕等。從客戶端檢測到潛在危險的Request.Form值
我從數據庫中提取記錄並將其分配給像下拉列表,文本框和按鈕之類的控件。將值分配給包含<
或>
的文本框並嘗試更新記錄時。它引發一個異常。例外是A potentially dangerous Request.Form value was detected from the client
。所以我嘗試使用htmlencode方法。
下面是我的代碼 在CS文件
public partial class Webform1 : System.Web.UI.Page
{
string strUrl="";
protected void Page_Load(object sender, EventArgs e)
{
// Fetching value from database and assigning to string
Textbox1.Text= dr["URL"].ToString();
// directly use string
//strUrl= dr["URL"].ToString();
}
protected void button_Click(object sender, EventArgs e)
{
string s2 ="";
string s3 = "";
strUrl= Textbox1.Text;
if ((strUrl.Contains("<")) || (strUrl.Contains(">")))
{
s2 = Server.HtmlEncode("<");
s3 = Server.HtmlEncode(">");
strUrl= strPingUrl.Replace("<", s2);
strUrl= strPingUrl.Replace(">", s3);
}
Textbox1.Text =strUrl;
// updation code
當我將嘗試插入它拋出分配值的TextBox如果我使用string.It工作的exception.Instead。我可以更新記錄。但我不想這樣。用戶可以更改文本框中的值。所以我想從文本框中獲取價值。
你檢查嗎? http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client?rq=1 – Ravimallya 2015-03-25 05:34:12
是的,我訪問該頁面。我不想使用這段代碼。 <的httpRuntime requestValidationMode = 「2.0」/> <結構> <頁validateRequest = 「假」/> 配置> –
2015-03-25 05:39:00
嘗試http://www.codeproject.com/Tips/423413/Submit -HTML-Text-with-Page-Validation-On-On-On – Amit 2015-03-25 06:13:12