Intermittent asp.net mvc exception: “A public action method ABC could not be found on controller XYZ.”

后端 未结 13 703
春和景丽
春和景丽 2020-12-02 04:57

I\'m getting an intermittent exception saying that asp.net mvc can’t find the action method. Here’s the exception:

A public action method \'Fill\' cou

13条回答
  •  一向
    一向 (楼主)
    2020-12-02 05:36

    I'v got the same problem in asp.net mvc. this error - 404 not found. I resolve problem this way - put this code in MyAppControllerBase (MVC)

        protected override void HandleUnknownAction(string actionName)
        {
            this.InvokeHttp404(HttpContext);
        }
    
        public ActionResult InvokeHttp404(HttpContextBase httpContext)
        {
            IController errorController = ObjectFactory.GetInstance();
            var errorRoute = new RouteData();
            errorRoute.Values.Add("controller", "Pages");
            errorRoute.Values.Add("action", "Http404");
            errorRoute.Values.Add("url", httpContext.Request.Url.OriginalString);
            errorController.Execute(new RequestContext(
                 httpContext, errorRoute));
    
            return new EmptyResult();
        }
    

提交回复
热议问题