How do I output raw html when using RazorEngine (NOT from MVC)

前端 未结 6 1684
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 04:34

I am trying to generate emails with HTML content. this content has already gone through sanitation so I am not worried in that regard, however when I call:

         


        
6条回答
  •  一整个雨季
    2020-12-24 04:44

    If you have a custom base class for your templates, you can code Write method to behave similar to normal MVC template: if the output value is IHtmlString it should not encode it.

    Here's the code I'm using in my TemplateBase class:

    // Writes the results of expressions like: "@foo.Bar"
    public virtual void Write(object value)
    {
        if (value is IHtmlString)
            WriteLiteral(value);
        else
            WriteLiteral(AntiXssEncoder.HtmlEncode(value.ToString(), false));
    }
    
    // Writes literals like markup: "

    Foo

    " public virtual void WriteLiteral(object value) { Buffer.Append(value); }

提交回复
热议问题