A potentially dangerous value Request.Form has been detected in the client

Asked

Viewed 15,160 times

7

I’m having trouble sending this type of input in the input field: &&&&%$&#_(@)(#_!**@#)24 R87R XDHNSIFN 89Q7201784 Dangerous Resquest.Form Error occurs.

Error message: inserir a descrição da imagem aqui

Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TesteInputValidation.Models;

namespace TesteInputValidation.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(Cartao t)
        {
            var teste = t;
            return View();
        }
    }
}

Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TesteInputValidation.Models
{
    public class Cartao
    {
        public string CartaoBeneficiario { get; set; }
    }
}

View

@model TesteInputValidation.Models.Cartao
@{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

<div class="row">
    @using (Html.BeginForm(null, null, FormMethod.Post, new {@id = "frmFiltro", @class = "smart-form"}))
    {
        @Html.TextBoxFor(model => model.CartaoBeneficiario, new { @class = "form-control", @id = "txtNumeroCartao" })

    <footer>
        <button id="enviar" type="submit" class="btn btn-primary wait-process">Enviar</button>
    </footer>
    }


</div>

If I take the validation will take all validations from Data Annotation?

There is a way to treat this error correctly?

1 answer

13


Decorate your method with the attribute ValidateInput

[HttpPost]
[ValidateInput(false)]
public ActionResult index()
{
   return view();
}

Maybe you need this on your Web.Config

<httpRuntime requestValidationMode="2.0"/>
  • But isn’t there any way you don’t need to disable Validate Input? some kind of Script or function in Razor that decodes html ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.