我在VS(C#和ASP.net)中编写以下代码:
using (StreamWriter streamWriter = File.CreateText(@"Example.aspx"))
{
streamWriter.WriteLine( "<pre>" + TextBox2.Text + "</pre>" );
}
这段代码打开example.aspx文件,并将TextBox2.text的值写入Example.aspx中。
但有一个问题 。当我将
<h1> </h1>
写入Textbox2.text时,出现错误。或当我将<i> </i>
写入textbox2.text时,出现相同的错误!我该怎么办? 。提前致谢 。
我的错误是:
A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$TextBox2="<h1> </h1>").
最佳答案
默认情况下,asp.net将阻止html代码作为文本框的输入,您必须在页面中设置此属性ValidateRequest="false"
详细示例:http://yourtahir.wordpress.com/2008/03/28/aspnet-not-allow-html-in-text-boxserver-error-in-application-a-potentialy-dangerous-requestform-value-was-detected/
关于c# - 用C#制作<h1> </h1>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4213980/