Alternative of Html.Raw in ASP.NET WebForms(ASP.NET WebForms 中 Html.Raw 的替代方案)
问题描述
我收到错误一个潜在的危险请求".. 在 Web 表单应用程序中,我尝试使用validatepage=false"和",然后我尝试了 Server.HtmlEncode,因此它将编码的 html 保存在数据库中.现在,当我通过 Server.HtmlDecode(DataContent.FieldValue("Contents", Container)) 在中继器控件中显示数据时,它显示了带有 html 标签的文本,例如 <p>asfd</p>...
I was getting error "A potential dangerous request" .. in Web Form application I have tried with "validatepage=false" and "" then i tried Server.HtmlEncode so it is saving encoded html in database. Now when i showed the data in Repeater control by Server.HtmlDecode(DataContent.FieldValue("Contents", Container)) It is showing text with html tags like <p>asfd</p>..
我该如何解决这个问题?在剃刀视图中 Html.Raw 工作正常,但在 webform 视图/ASP.NET 中有什么替代方案?有人可以帮忙吗?
how i can resolve this issue? In razor view Html.Raw works fine but what is alternative in webform view / ASP.NET? Can anybody help?
推荐答案
你可以使用 <%= value %> 这将不对值进行编码.
you can use <%= value %> which will not encode the value.
或者您可以实现自己的 HTML.Raw 版本
or you can implement your own version of HTML.Raw
Html.Raw 返回一个与字符串几乎相同的 IHtmlString 实例,但 ASP.net 不编码 IHtmlString.
Html.Raw returns an IHtmlString instance which is almost same as string but ASP.net doesn't encode IHtmlString.
复制 HTML.Raw() 的简单函数
Simple function to replicate HTML.Raw()
/// <summary>
/// Stops asp.net from encoding the source HTML string.
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IHtmlString HTMLRaw(string source)
{
return new HtmlString(source);
}
这篇关于ASP.NET WebForms 中 Html.Raw 的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET WebForms 中 Html.Raw 的替代方案
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 将数据集转换为列表 2022-01-01
