2012-11-29 25 views
0

我有這張簡單的桌子。其中一個字段被稱爲內容Nvarchar(最大)如何通過webform將部分HTML代碼提交給SQL Server數據庫?

如果我使用SQL Server Management直接在數據庫中編輯該字段,那麼在下面添加下面的文本,它會很好地存儲它。

文字:

Do you open the menu at a restaurant ever expanding multi-cultural tourist hub, Chinatown has a lot to offer to meet your culinary desires, from China and beyond.<br /></br>This tour will be the first in a series the food. 

但是,如果我試圖提交上述使用ASPX頁面的網頁表單到數據庫相同的文字,我得到下面的錯誤,我承擔的,因爲2 <br />代碼

從 客戶端檢測到有潛在危險的Request.Form值(tbTourDetails =「... nd beyond。
This tour ...」)。

我該如何解決這個問題,這樣我就可以有一個Web表單,將HTML部分提交給我的數據庫?

問候 茶

+0

做在存儲和解碼之前進行html解碼。 – CodeSpread

回答

0

既然你想保存的HTML代碼,您需要添加requestValidationMode =「2.0」到web.config的的httpRuntime配置部分。

<httpRuntime requestValidationMode="2.0" /> 

現在存儲之前對其進行編碼:

String TestString = "This is a <Test String>."; 
String EncodedString = Server.HtmlEncode(TestString); 

和顯示爲文本對其進行解碼:

Label1.Text = HttpUtility.HtmlDecode(dbValue); 

參考文獻: HtmlEncode Method HtmlEncode, HtmlDecode

+0

我會在接下來的幾天給它一個,謝謝。 – TeaDrinkingGeek

相關問題