0

我有代码

protected void Application_Error(object sender, EventArgs e)
    {
        HttpContext ctx = HttpContext.Current;
        Exception ex = ctx.Server.GetLastError();
        ctx.Response.Clear();

        var viewResult = new ViewResult();

        if (ex.GetType() != typeof(SecurityException))
        {
            RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
            IController controller = new ModuleController();
            var context = new ControllerContext(rc, (ControllerBase)controller);                

            var httpException = ex as HttpException;
            if (httpException != null)
            {
                switch (httpException.GetHttpCode())
                {
                    case 404:
                        viewResult.ViewName = "Error404";
                        Response.StatusCode = 404;
                        break;

                    case 500:
                        viewResult.ViewName = "Error500";
                        Response.StatusCode = 500;
                        break;

                    default:
                        viewResult.ViewName = "Error";
                        Response.StatusCode = httpException.GetHttpCode();
                        break;
                }
            }
            else
            {
                viewResult.ViewName = "Error";
            }

            viewResult.ViewData.Model = new HandleErrorInfo(ex, context.RouteData.GetRequiredString("controller"), context.RouteData.GetRequiredString("action"));
            viewResult.ExecuteResult(context);
            ctx.Server.ClearError();
        }
        else
        {
            var context = new ControllerContext { RouteData = new RouteData() };
            context.RouteData.Values.Add("controller", "Security");
            context.Controller = new SecurityController();
            HttpCookie cookie = this.mebershipService.GetCookie();
            cookie.Expires = DateTime.Now.AddDays(-1);
            this.Context.Response.Cookies.Add(cookie);
            viewResult.ViewName = "HackedDetect";
            Response.StatusCode = 403;
            viewResult.ExecuteResult(context);
            ctx.Server.ClearError();
        }
    }

处理SecurityException时,调用与系统无关的控制器(为了不绕圈子)就代码viewResult.ExecuteResult(context);是一个 NotImplementedException 但我不清楚哪个方法或操作没有定义。

这就是从错误中复制到剪贴板的内容

System.NotImplementedException 未由用户代码处理
HResult = -2147467263
消息 = 方法或操作未实现。
Source = System.Web
StackTrace:
in System.Web.HttpContextBase.get_Response()
in System.Web.Mvc.ViewResultBase.ExecuteResult (ControllerContext context)
in SGN.Web.MvcApplication.Application_Error (Object sender, EventArgs e) in C:\ Project\SGN\SGN.Web\Global.asax.cs: System.Web.HttpApplication.RaiseOnError() InnerException
中System.EventHandler.Invoke(Object sender,EventArgs e)第142行:

更新

我会写下我要做什么来得到这个错误

我创建了自定义身份类,并在初始化时验证了 cookie。如果 cookie 不验证我创建 SecurityException

4

0 回答 0