【发布时间】:2011-09-12 13:23:30
【问题描述】:
我已经看过几篇关于关闭控制器/操作的 HttpRequestValidation 以解决此错误的帖子,但我真的希望它在大多数情况下都启用。我想绕过验证的情况很少,我愿意在其周围包裹一个 try/catch 块:
string searchTerm = string.Empty;
try {
searchTerm = Request.QueryString["q"];
} catch (HttpRequestValidationException ex) {
// What can I do here to capture the value? Is parsing the error message the only way?
// Seems like ex.Data property would be a good place for Microsoft to stick values if
// people wanted to do something with them, but ex.Data is empty.
}
同样,这仅适用于表单中的某些字段,因此我不想禁用对整个控制器或操作的验证。我希望为我没有专门处理的字段提供额外的保护。
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-3 error-handling