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 的替代方案
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
