Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access unvalidated items in the Request.Form collection in MVC 3

I am using ASP.NET MVC 3 with .NET 4.0. I have a model on which one of the properties requires that HTML content be allowed. I have placed the AllowHtml attribute on my model property which allows HTML on that property. That works by itself.

I am also using the Uploadify flash uploader on other parts of my website. Due to problems with flash and sessions, I'm using some code similar to the code in a swfupload example to allow my file upload access to session data. Basically I'm accessing the Request.Form collection directly in the Application_BeginRequest handler.

The problem I'm running into is that when the form that allows HTML is posed I get a HttpRequestValidationException when the code in the Application_BeginRequest handler access the Request.Forms[key] collection.

Like I said in the beginning, I've tried the AllowHtml attribute. I've also tried disabling validation at the action and controller level using the ValidateInput(false) attribute, but I believe I'm too early in the request life cycle for those to apply. Is there anyway to access the Request.Form collection containing "potentially dangerous" data without disabling request validation for the entire site?

like image 851
heavyd Avatar asked Sep 17 '12 21:09

heavyd


People also ask

What is formcollection?

The Form collection is used to retrieve the values of form elements from a form that uses the POST method.

How to add validation in ASP.NET Core MVC?

Add validation rules to the movie model DataAnnotations also contains formatting attributes like DataType that help with formatting and don't provide any validation. Update the Movie class to take advantage of the built-in Required , StringLength , RegularExpression , and Range validation attributes.

What is ASP validation for?

ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or contradictory data don't get stored. ASP.NET provides the following validation controls: RequiredFieldValidator. RangeValidator.


1 Answers

You asking about something like this: Validate request with Request.Unvalidated() in ASP MVC 3 RC and .NET 4 ?

Request.Unvalidated().Params[""]
like image 163
webdeveloper Avatar answered Nov 11 '22 04:11

webdeveloper