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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:48:58+00:00 2026-05-23T22:48:58+00:00

Any suggestions for best practice on validating/cleaning user input in ASP.NET MVC. It seems

  • 0

Any suggestions for best practice on validating/cleaning user input in ASP.NET MVC. It seems ValidateInput will almost always need to be set to False since it cant be handled from within the MVC framework (the error is thrown even before the Action Method is fired).

So how should the input be validated for malicious input. Do we have to manually screen each input and check it for characters such as <, >, ” etc
How about if we only wish to allow some types of input such as tags but forbid and other inputs? This must be a pretty common requirement of a web app now, but I can’t see much in ASP.NET MVC to automate this.

  • 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-05-23T22:48:58+00:00Added an answer on May 23, 2026 at 10:48 pm

    So how should the input be validated for malicious input. \

    It depends on what your application is doing with this input. If you are storing it in a relational database for example, well, as long as you use parametrized queries and properly encode the user request, relational database don’t care about storing for example alert('foo'); in a given column. When you might get into trouble is when you try to fetch the result stored in this database and show it on some view. It is at that moment that you must ensure that the result is properly HTML encoded.

    So for example let’s suppose that you have stored some hyper dangerous string in your data store and you want to display it on your view. If you were using the Razor view engine you would simply:

    @Html.DisplayFor(x => x.SomeProperty)
    

    which will take care of properly HTML encoding the value of SomeProperty so that you don;t have to worry about.

    And if you were using the WebForms view engine:

    <%= Html.DisplayFor(x => x.SomeProperty) %>
    

    So, as you can see there are two critical moments where you should be careful with the user input:

    • always use parametrized queries if you are storing this user input into a relational database
    • always HTML encode the value you have stored when time comes to render it on some view
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any suggestions for good open source asp.net (C#) apps out there which meet as
Does anyone have any suggestions for a best practice or preferred way of rolling
Possible Duplicate: mysql datatype for telephne number and address Any suggestions on best practice
Any suggestions on the best way to ensure thread safety when changing the properties
Any suggestions on the best way to display this table on an Android platform?
What are the best file permission settings for PHP scripts? Any suggestions on ways
I'm looking for the best (free/cheap) international weather PHP API out there. Any suggestions?
What is the best practice when serving files from the Zend Framework MVC? These
I am getting the following Best Practice error in Dynamics AX 2009 for any
i have taken over an asp.net mvc and i there are a lot of

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.