MVC 5错误找不到路径'/ setpassword'的控制器

时间:2018-09-13 15:06:31

标签: asp.net asp.net-mvc razor error-handling controller

我想知道如何控制此错误,当我想重定向到视图错误时,html代码未呈现,因此当我尝试键入此http://localhost:5455/ControllerNotFound时,而是键入http://localhost:5455/Controller/Whatever运行正常。

No rendering ErrorPage when controller NotFound

Erorr page is Showup when action is NotFound

Global.asax中的应用程序错误处理程序

void Application_Error(object sender, EventArgs e)
    {
        brMessaging.Util ObjbsUtil = new brMessaging.Util();
        brMessaging.LogError ObjbsLogError = new brMessaging.LogError();
        try
        {
            Exception exception = Server.GetLastError();

            if (exception != null)
            {
                Server.ClearError();

                var routeData = new RouteData();
                routeData.Values.Add("controller", "ErrorHandler");
                routeData.Values.Add("action", "Error");
                routeData.Values.Add("exception", exception);

                if (exception.GetType() == typeof(HttpException))
                {
                    routeData.Values.Add("statusCode", ((HttpException)exception).GetHttpCode());
                }
                else
                {
                    routeData.Values.Add("statusCode", 500);
                    var inputData = new Dictionary<string, string>() { {"IP: ", ObjbsUtil.getUserIp(Request) } };
                    ObjbsLogError.InsertLog(new SystemFramework.Entities.SFException(exception, 0, "Global", "Application_Error", (int)SystemFramework.Enumerator.PortalName.OV_Messaging,
                    false, Request.Url.ToString(), "Error capturado en el Global.asax", 0, inputData));
                }

                IController controller = new ErrorHandlerController();
                controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
            } 
        }
        catch (Exception)
        {

        }
    }

0 个答案:

没有答案