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

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

    In ASP.NET, you can catch the exception and do something about it, such as displaying a friendly message or redirect to another page... Also there is a possibility that you can handle the validation by yourself...

    Display friendly message:

    protected override void OnError(EventArgs e)
    {
        base.OnError(e);
        var ex = Server.GetLastError().GetBaseException();
        if (ex is System.Web.HttpRequestValidationException)
        {
            Response.Clear();
            Response.Write("Invalid characters."); //  Response.Write(HttpUtility.HtmlEncode(ex.Message));
            Response.StatusCode = 200;
            Response.End();
        }
    }
    

提交回复
热议问题