Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:21:20+00:00 2026-06-10T20:21:20+00:00

So, I thought I was a veteran ASP.NET WebForms developer; however, I came across

  • 0

So, I thought I was a “veteran” ASP.NET WebForms developer; however, I came across this recently and was (unpleasantly) surprised that the output is not escaped:

<asp:Label Text='<%# Eval("UserData") %>' runat="server" />

Imaging where the Eval returns "<h1>joke is on you" or something more malicious to the correct rendering/security of the page.

The reason there is a Label instead of the <%# %> directly was so that, as incorrectly presumed, the contents of “UserData” would be correctly escaped for HTML. However, this apparently is not the case and the above scenario results in <h1> elements being created in the HTML markup.

Then the question can be distilled as:

Given arbitrary user input, that is to be presented as “plain text”, what is an easy/reliable/secure method to insert data into the page (in a span) with correct escaping?

As per above, it should run in the context of a data-bound control. I am aware of HttpUtility.HtmlEncode, but I would like to entertain the idea of still using a control – perhaps there is a standard control for this task that I missed – to represent this case safely, without the need for wrapping the Eval. If this is misguided, based on logic or experience, it would be good to include in replies. I would not reject the notion that my use of Label in this case is entirely inappropriate.

Unfortunately, due to needing to run in a SharePoint 2010 context, I target ASP.NET for .NET 3.5, and not ASP.NET 4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:21:22+00:00Added an answer on June 10, 2026 at 8:21 pm

    What about:

    <asp:Label Text='<%#: Eval("UserData") %>' runat="server" />
    

    This escapes the output of the eval, this only works in .NET 4.

    For .NET 3.5 a solution can be:

    CodeBehind:

    public object EvalEncode(object container, string expression)
    {
      string ouput = DataBinder.Eval(container, expression).ToString();
      return HttpUtility.HtmlEncode(ouput);
    }
    

    MarkUp:

    <%# EvalEncode(Container.DataItem, "Text") %>
    

    Instead of using HttpUtility.HtmlEncode, it’s maybe better to use the AntiXSS library. For .NET 4 users it’s already backed into the framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I would be smart and create member functions that accepted output iterators.
I thought the difference is that declaration doesn't have parameter types... Why does this
I thought that I understood how MacOSX manages memory, but recently I’ve become baffled
I thought I heard that py2exe was able to do this, but I never
I thought that there was some way in .net 3.0 to give an array
Thought my range of search options would easily find this. I wish to combine
I thought I had resolved this but I obviously haven't and was hoping someone
I thought the following script will create div element but I got nothing output
I thought this would be fairly simple but it turns out not to work
I thought I'd find more about this topic but I didn't. I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.