不涉及正则表达式的解决方案,只需将其添加到您的 Global.asax.cs:
protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (e.Message == "A potentially dangerous Request.Path value was detected from the client (:).")
e.Dismiss();
}
// this method may also be useful
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (e.Message == "A potentially dangerous Request.Path value was detected from the client (:).")
{
// do something
}
}
或者你可以结合这两种方法:
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs args)
{
Filter(args);
}
void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs args)
{
Filter(args);
}
void Filter(ExceptionFilterEventArgs args)
{
if (args.Exception.GetBaseException() is HttpRequestValidationException)
args.Dismiss();
}