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 9112339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:42:43+00:00 2026-06-17T03:42:43+00:00

I have a ‘Description’ field in a form. I would like the user to

  • 0

I have a ‘Description’ field in a form. I would like the user to not be restricted from using special characters in this field.

As such, I would like to be able to POST the following data from my client to my server, save to the database, and be able to render properly again:

Test Description (&&%$^&^()^&&$& 87566467679089765
?<>?<>?<>?<>”:”;’;’;’][][][][{}{}{}

I did some reading on the subject, but it seems like I have more options than I expected. I would like to make sure I do this properly for security’s sake.

In my model, I’ve tagged my Description property with the AllowHtml attribute:

[DisplayFormat(ConvertEmptyStringToNull = false), AllowHtml]
public string Description { get; set; }

This allows the above data to POST to my Controller, but doesn’t address the heart of the issue. I now believe I need to sanitize my input. I believe this means that I need to leverage the HttpUtility library.

Looking at HttpUtility, I see a ton of methods:

  • HtmlAttributeEncode
  • HtmlEncode
  • UrlEncode

According to this post there doesn’t seem to be much difference between HtmlEncode and UrlEncode.

I’m wondering a few things:

  • Is using HttpUtility the correct choice here?
  • Is it fine to not do any processing of my input before POSTing? (Can I do all my encoding server-side?)
  • Should I be using Microsoft anti-xss libraries instead of HttpUtility?

and just generally any other pitfalls I might not have been made privvy.

UPDATE:

Here’s my model:

<div class="detailsRow optional">
    <%= Html.LabelFor(model => model.Description, new { @class = "descriptionLabel" }, Model.DescriptionLabel)%>
    <%= Html.TextAreaFor(model=> model.Description) %>
</div>

and my controller method:

public ActionResult SaveNewOrderDetails(NewOrderDetailsModel orderDetailsModel)
{
    string description = orderDetailsModel.Description;
    //Successfully got description
    //Example code:
    Order order = new Order(description);
    order.Save();

    return Json(new { id = order.ID, name = order.Name });
}

after my code passes the ‘return Json’ statement, I am greeted with another error:

A potentially dangerous Request.Form value was detected from the
client
(Description="…>?<>?<>?<><?>":";’;’;’][][][][…").

My understanding is that this should not be occurring. Any places I should check?

UPDATE2: Unable to get AllowHtml to work. I’m going to revisit this when we upgrade to MVC4.

  • 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-17T03:42:44+00:00Added an answer on June 17, 2026 at 3:42 am

    I now believe I need to sanitize my input.

    No, you are fine as far as receiving the user input and storing it into the database is concerned (assuming you have used parametrized queries which you should always do). The [AllowHtml] attribute will give you the possibility to enter any characters. If you wanted to sanitize the characters that the user could enter simply use a regular expression validator (I probably wouldn’t bother with that):

    [DisplayFormat(ConvertEmptyStringToNull = false)]
    [AllowHtml]
    [RegularExpression("PUT YOUR REGEX HERE")]
    public string Description { get; set; }
    

    You should be careful when you are rendering the value you have read from the database back to a view. You should make sure you always HTML encode it. For example the <%: function does that out of the box.

    So here’s a safe way to display it:

    <div>
        <%: Model.Description  %>
    </div>
    

    Be careful to never do that:

    <div>
        <%= Model.Description  %>
    </div>
    

    because this will not HTML encode the output and your site becomes vulnerable to XSS.

    And here’s another safe way using the DisplayFor helper:

    <div>
        <%= Html.DisplayFor(x => x.Description) %>
    </div>
    

    Also if you want to render this in an editable field or text area simply use the corresponding helper:

    <div>
        <%= Html.TextAreaFor(x => x.Description) %>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
Have got a method which returns IEnumerable<User> which I have been using Linq /
Have a script to add / remove options from a select field -- the
Have a look at the menu link Produkter on http://marckmann.se/ I would like to
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
have a nice day. I got problem when trying to create an image from
Have not done this before, so obviously I suck at it. Here 64 pixels
Have a photography site that I want to prevent image copying from. How can
Have not done this before ( except in java , look how Steve McLeod
Have have this line of code in my form when I create a new

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.