HTMLencode HTMLdecode

后端 未结 3 1728

I have a text area and I want to store the text entered by user in database with html formatting like paragraph break, numbered list. I am using HTMLencode and HTMLdecode fo

3条回答
  •  悲&欢浪女
    2021-01-13 14:54

    That's not what HtmlEncode and HtmlDecode do. Not even close.

    Those methods are for "escaping" HTML. < becomes <, > becomes >, and so on. You use these to escape user entered input in order to avoid Cross-Site Scripting attacks and related issues.

    If you want to be able to take plain-text input and transform it into HTML, consider a formatting tool like Markdown (I believe that Stack Overflow uses MarkdownSharp).

    If all you want are line breaks, you can use text.Replace("\r\n", "
    ")
    , but handling more complex structures like ordered lists is difficult, and there are already existing tools to handle it.

提交回复
热议问题