Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.Raw is not working asp.net mvc

Tags:

I have some html stored in a table. here is some sample data

<p><span style="font-size: small; color: #ff0000;"><span style="font-size: small;"> <span style="font-size: large; color: #000000;">ਮਾਂ</span><br />  <br />ਚਾਵਾਂ ਸਧਰਾਂ ਦੇ ਨਾਲ ਮਾਏ ਜੋ ਤੂੰ ਬੂਟਾ ਲਾਇਆ,<br />ਦੇ ਮਮਤਾ ਦਾ ਪਾਣੀ ਅੱਜ ਓਹ ਭਰ ਜੋਬਨ ਤੇ ਆਇਆ,<br /> 

I am trying to display on page, I am using asp.net mvc razor view and using

@Html.Raw(blog.Body) 

but its not working. can someone help, what is the reason.

Thanks

Parminder

like image 913
Parminder Avatar asked Mar 04 '12 15:03

Parminder


People also ask

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 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.

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

kindly try this:

@Html.Raw(HttpUtility.HtmlDecode(blog.Body)); 

and let me know if it worked.

like image 134
Mohammed Swillam Avatar answered Sep 28 '22 08:09

Mohammed Swillam