如何处理 MVc 中潜在危险的请求?
我在 global.asax 中使用以下内容来处理错误,但它没有捕获这些错误。
它捕获其他错误类型。`
else if (httpException is HttpRequestValidationException)
{
routeData.Values.Add("action", "General");
}`
有人在 MVc 中做过这个吗?
最佳答案
在mvc中,一般HandleErrorAttribute Class用于处理异常并根据异常类型返回具体 View
[HandleError(ExceptionType = typeof(HttpRequestValidationException), View = "RequestIsNotValid")]
public class SomeController : Controller {}
当 web.config 中的 customErrors 模式为“on”或“remote”时,这将重定向到 RequestIsNotValid View 。当然,在“远程”期间,它只会显示给远程用户。如果您想在开发过程中进行测试,请设置 customErrors mode= 'on'
关于asp.net-mvc-3 - 处理潜在危险请求-MVC-ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6622158/