Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RazorEngine: cannot use Html.Raw

Tags:

using RazorEngine outside asp.net I'm experiencing this error when I try to write raw html by using @Html.Raw("html string here"):

Unable to compile template. The name 'Html' does not exist in the current context

Can you help me?

Thanks!

like image 427
ff8mania Avatar asked May 12 '14 07:05

ff8mania


People also ask

Why not use HTML Raw?

Raw can result in a XSS vulnerability being exploitable since an attacker can craft a special URL containing a malicious JavaScript payload that will be executed by the victim's browser if he or she sends an invalid 2FA confirmation code.

Can we use HTML Raw?

Raw method does not work and I have to use HttpUtility. HtmlDecode(EncodedContent) before I use Html.

What is HTML raw in MVC?

The Html. Raw Helper Method is used to display HTML in Raw format i.e. without encoding in ASP.Net MVC Razor. Configuring Bundles. Please refer the following article for complete information on how to configure Bundles in ASP.Net MVC project. Using Bundles (ScriptBundle) in ASP.Net MVC Razor.

Why we use HTML Raw?

Using Html. Raw allows you to output text containing html elements to the client, and have them still be rendered as such. Should be used with caution, as it exposes you to cross site scripting vulnerabilities.


1 Answers

The solution has been found here: https://github.com/Antaris/RazorEngine/issues/34

It's enough to use @(new RawString("html string here")) or @Raw("html string here") instead of @Html.Raw("html string here").

I hope this helps! Bye

like image 162
ff8mania Avatar answered Sep 28 '22 22:09

ff8mania