【问题标题】:How to store html or any other code to database and retrieve display in asp.net webpage如何将 html 或任何其他代码存储到数据库并在 asp.net 网页中检索显示
【发布时间】:2016-07-29 07:22:13
【问题描述】:
<script type ='text/Javascript'>
  var _gap=_gap||[];<br/>
 _gap.push(['_setAccount','UA-xxxxxxxxx-x']);
 _gap.push(['_trackPageview']);
</script>

提交代码到数据库表单:

此表单包含一个文本框和一个按钮,当我单击此按钮时,我在文本框中输入的任何代码将 存储到数据库并从数据库中检索该代码并显示在我的另一个 asp.net 网页中,如下图所示

下一个表格

[以这种形式,代码从数据库中检索并以语法显示 荧光笔格式][1][1]:http://i.stack.imgur.com/zBU8L.jpghttp://i.stack.imgur.com/zBU8L.jpg'/>

【问题讨论】:

    标签: asp.net .net asp.net-mvc asp.net-mvc-4 c#-4.0


    【解决方案1】:

    将脚本或任何 html 作为 byte[]

    添加到数据库

    步骤:

    1. 将您的脚本转换为 byte[] 并将其保存为数据库。

    2. 检索字节[]并转换为原始然后显示在第二页。

    【讨论】:

    • 能否请您发布任何属于我要求的示例代码
    【解决方案2】:

    我终于得到了答案

    第 1 步:首先在页面指令中添加这个 ValidateRequest="false"

    第 2 步: 在 asp.net 的 web.config 文件中添加此代码

    <system.web>
        <httpRuntime requestValidationMode="2.0" />
    </system.web
    

    第三步:按钮点击事件代码

       protected void Button1_Click(object sender, EventArgs e)
        {            
            string html = TextBox1.Text;
            Label1.Text = html;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-24
      • 2013-05-02
      • 2015-06-01
      • 2018-02-26
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多