将错误消息添加到CustomValidator

时间:2011-11-17 04:02:24

标签: asp.net

我想通过使用下面的方法捕获实现IHttpHandler的potentail脚本攻击来向CustomValidator添加一条错误消息,但它似乎只是因为页面空白,任何想法而终止页面?

public override void ProcessRequest(HttpContext context)
    {
        try
        {
            base.ProcessRequest(context);
        }
        catch (HttpRequestValidationException ex)
        {
           DisplayCustomMessageInValidationSummary("< or > characters are not allowed");    
        }
    }

private void DisplayCustomMessageInValidationSummary(string message)
{

    CustomValidator CustomValidatorCtrl = new CustomValidator();
    CustomValidatorCtrl.IsValid = false;
    CustomValidatorCtrl.ErrorMessage = message;
    this.Page.Controls.Add(CustomValidatorCtrl);

}  

由于 达伦

0 个答案:

没有答案