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 的替代方案
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
