1

Say I have a ListView on my aspx page. I need to filter out any possible XSS data that might have snuck inside, but I can't Server.Encode on "eval" whatever that is.

I have code like this, and I don't know how to XSS filter gridviews.

<asp:ListView ID="MyList" runat="server" DataSourceID="MySource" DataKeyNames="ObjectID" OnItemCommand="MyList_OnItemCommand">
        <ItemTemplate>
            <tr id="row" runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "row" : "altrow" %>'>
                <td align="left">
                    <%# Eval("Name") %>
                </td>

See the problem? Eval("Name") is not XSS filtered. What do I do?

2 Answers 2

1

You can call HttpUtility.HtmlEncode(), which is a static method:

<%# HttpUtility.HtmlEncode(Eval("Name")) %>
Sign up to request clarification or add additional context in comments.

Comments

1
<%# Server.HtmlEncone(Eval("Name")) %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.