Trouble using antixss on .net 3.5 aspx page

May 27, 2011 at 12:42 AM

Hi there,

I recently downladed and installed antixss 4.0. I dropped the dll in a lib folder in the project and added a reference to the dll. I am using Microsoft.Security.Application per the instructions. On the .cs code behind page the AntiXss.HtmlEncode(string) works like a charm. However, when I try to use it like <%# AntiXss.HtmlEncode(Eval("name")) %> I get the following error: The name 'AntiXss' does not exist in the current context

When I try to add the Import directive for Microsoft.Security.Application, I get the following error: The type or namespace name 'Security' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Thanks for your help.

 

Coordinator
May 27, 2011 at 3:21 PM

If you're using it in the .aspx you'll need to import the namespace in the page itself;

<%@ Import Namespace="Microsoft.Security.Application" %>

Or you could just fully qualify it every time, but that's tiresome.

You could also, if you're going to use it on every page automatically import the namespace. To do this you need to edit your web.config, specifically the pages element.

<pages ... >
    <namespaces>
        <add namespace="Microsoft.Security.Application"/>
    </namespaces>
    ...
</pages>
       

May 27, 2011 at 4:26 PM

Thanks for the reply. I am sure I am missing something simple. When I add the

<%

@ Import Namespace="Microsoft.Security.Application"

%>

 or I add it in the web.config<pages>...

I get the following error:

 

<!--Import Namespace="Microsoft.Security.Application"-->

 The type or namespace name 'Security' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

I added the AntiXSSLibrary.dll to a folder within the solution, and reference the .dll from there. 

Thanks again for your help.

May 27, 2011 at 5:14 PM

I got it figured out. The problem was, the .dll dropped into the project bin, but I had to copy it into the virtual directory bin. Sometimes it's the simple things that drive you crazy.