我有一个像这样的简单 Controller :
[CustomFilter()]
public ActionResult Index( int? page ) {
return View();
}
public class CustomFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting( ActionExecutingContext filterContext ) {
base.OnActionExecuting( filterContext );
}
public override void OnActionExecuted( ActionExecutedContext filterContext ) {
base.OnActionExecuted( filterContext );
}
}
在主页 (ASPX) 中,如果我输入 http://localhost/home/index?page=<script>
(我猜是 XSS 的一个例子)而不是 http://localhost/home/index?page=7
然后会出现红色页面(因为在 Visual Studio 中我已经安装了 AntiXSS 插件)。
如何为此类攻击创建自定义过滤器并返回上一页而不显示红色页面(有错误)? 或者不可能?
最佳答案
不,永远不会调用过滤器。你可以在 Application_Error
检查这个问题:ASP.NET MVC app custom error pages not displaying in shared hosting environment
看问题和答案。
关于c# - 为 Controller Action 参数创建过滤属性抗XSS攻击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9061831/