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

前端 未结 30 2130
刺人心
刺人心 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:39

    You can catch that error in Global.asax. I still want to validate, but show an appropriate message. On the blog listed below, a sample like this was available.

        void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
    
            if (ex is HttpRequestValidationException)
            {
                Response.Clear();
                Response.StatusCode = 200;
                Response.Write(@"[html]");
                Response.End();
            }
        }
    

    Redirecting to another page also seems like a reasonable response to the exception.

    http://www.romsteady.net/blog/2007/06/how-to-catch-httprequestvalidationexcep.html

提交回复
热议问题