A potentially dangerous Request.Form value was detected from the client

前端 未结 30 2809
刺人心
刺人心 2020-11-21 05:24

Every time a user posts something containing < or > in a page in my web application, I get this exception thrown.

I don\'t want to go

30条回答
  •  生来不讨喜
    2020-11-21 05:49

    The other solutions here are nice, however it's a bit of a royal pain in the rear to have to apply [AllowHtml] to every single Model property, especially if you have over 100 models on a decent sized site.

    If like me, you want to turn this (IMHO pretty pointless) feature off site wide you can override the Execute() method in your base controller (if you don't already have a base controller I suggest you make one, they can be pretty useful for applying common functionality).

        protected override void Execute(RequestContext requestContext)
        {
            // Disable requestion validation (security) across the whole site
            ValidateRequest = false;
            base.Execute(requestContext);
        }
    

    Just make sure that you are HTML encoding everything that is pumped out to the views that came from user input (it's default behaviour in ASP.NET MVC 3 with Razor anyway, so unless for some bizarre reason you are using Html.Raw() you shouldn't require this feature.

提交回复
热议问题