Upendra Pratap Shahi

Upendra Pratap Shahi

  • 187
  • 10.4k
  • 2.1m

How to implement AntiXSS library in .net 4.5

Nov 9 2016 9:16 AM
I am facing issue when implementing AntiXSS library in .net 4.5.
Previously I've used this in .net4.0 from nuget package, when update from nuget package then this add two DLL, AntiXssLibrary and HtmlSanitizationLibrary DLL. 
After adding this I've used below name space :
 
using Microsoft.Security.Application;
 
after this I have called this as below :
 
string finalText1 = Sanitizer.GetSafeHtmlFragment(TesxtBox1.Text.Trim()); 
 
In textbox, I've entered below string :
 
XSS test <script>alert('upendra');</script> 
 
and this throw below output:
 
XSS test 
 
but when I've used in .net 4.5 then unable to find this method.
In 4.5 :
 
using System.Web.Security.AntiXss; 
 
string finalText = AntiXssEncoder.HtmlEncode(esxtBox1.Text.Trim(),true); 
 
and this encode XSS test <script>alert('upendra');</script>
 
in XSS test &lt;script&gt;alert('upendra');&lt;/script&gt; 
 
How to get desired output as throw in .net4.0 in 4.5 without using any DLL because AntiXSS is already inbuilt in .net 4.5.