Alternative of Html.Raw in ASP.NET WebForms

前端 未结 2 1083
清歌不尽
清歌不尽 2021-01-01 20:47

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 sa

相关标签:
2条回答
  • 2021-01-01 21:00

    you can use <%= value %> which will not encode the value.

    or you can implement your own version of HTML.Raw

    Html.Raw returns an IHtmlString instance which is almost same as string but ASP.net doesn't encode IHtmlString.

    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);
        }
    
    0 讨论(0)
  • 2021-01-01 21:02

    You can use asp:Literal with Mode=PassThrough

    0 讨论(0)
提交回复
热议问题