我有一个具有自定义 HandleErrorAttribute 的 MVC3 应用程序,以便我可以通过电子邮件发送错误。我经常收到“从客户端检测到潜在危险的 Request.Form 值”,但它只显示导致异常的表单值的前几个字符。我想查看输入的整个表单值,以便更好地了解输入是恶意的还是用户意外的。但是,当我尝试在 HandleErrorAttribute 中提取表单值时,它会引发相同的错误!知道如何从 Request.Form 获取表单值而不在我的异常处理程序中引起验证吗?
public class HandleErrorLogAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
base.OnException(context);
//Record Error
string errorDetails = HttpUtility.HtmlEncode(context.Exception.ToString());
// Throws "otentially dangerous..." error here
foreach (var key in context.RequestContext.HttpContext.Request.Form.AllKeys)
{
errorDetails += key + "=" + HttpUtility.HtmlEncode(context.RequestContext.HttpContext.Request.Form[key]);
}
// Send Email with errorDetails
}
}