Asp.net mvc flashing exception: "Public ABC action method not found on XYZ controller."

I get an interrupted exception saying that asp.net mvc cannot find an action method. The exception is:

The public Fill action method cannot be found on the controller 'Schoon.Form.Web.Controllers.ChrisController'.

I think I configured the routing correctly, because this application works most of the time. Here is the controller action method.

[ActionName("Fill")] [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post), UserIdFilter, DTOFilter] public ActionResult Fill(int userId, int subscriberId, DisplayMode? mode) { //… } 

Route:

 routes.MapRoute( "SchoonForm", "Form/Fill/{subscriberId}", new { controller = "ChrisController", action = "Fill" }, new { subscriberId = @"\d+" } ); 

And here is the stack:

System.Web.HttpException: The publication of the Fill action method cannot be found on the controller 'Schoon.Form.Web.Controllers.ChrisController. in System.Web.Mvc.Controller.HandleUnknownAction (String actionName) in C: \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc \ Controller.cs: line 197 on System.Web.Mvc.Controller.ExecuteCore () in C : \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc \ Controller.cs: line 164 to System.Web.Mvc.ControllerBase.Execute (RequestContext requestContext) in C: \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc ControllerBase.cs: line 76 on System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute (RequestContext requestContext) in C: \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc \ ControllerBase.cs: line 87 in System.Web.Mvc.MvcHandler.ProcessRequest (HttpContextBase httpContext) in C: \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc \ MvcHandler.cs: line 80 on System.Web.Mvc.MvcHandler.Cpcontext in C: \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc \ MvcHandler.cs: line 68 on System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest (HttpContext httpCont ext) to C: \ DEV \ ThirdParty \ MvcDev \ SRC \ SystemWebMvc \ Mvc \ MvcHandler.cs: line 104 on System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute () in System.WebApppp.ppeb .ExecuteStep (IExecutionStep step, Boolean & completedSynchronously)

Here is an example of my filters, they all work the same way:

 public class UserIdFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { const string Key = "userId"; if (filterContext.ActionParameters.ContainsKey(Key)) { filterContext.ActionParameters[Key] = // get the user id from session or cookie } base.OnActionExecuting(filterContext); } } 

Thank you, Chris

+80
exception asp.net-mvc
Nov 16 '09 at 22:12
source share
12 answers

We have found the answer. We looked through our weblogs. This showed that we received some strange http actions (verbs / methods) such as OPTIONS, PROPFIND and HEAD.

This is apparently the cause of some of these exceptions. This explains why it is intermittent.

We reproduced the problem using the curl.exe tool:

 curl.exe -X OPTIONS http://localhost/v2.3.1.0/(S(boztz1aquhzurevtjwllzr45))/Form/Fill/273 curl.exe -X PROPFIND http://localhost/v2.3.1.0/(S(boztz1aquhzurevtjwllzr45))/Form/Fill/273 curl.exe -X HEAD http://localhost/v2.3.1.0/(S(boztz1aquhzurevtjwllzr45))/Form/Fill/273 

The fix we used was to add an authorization section to web.config:

 <authorization> <deny users="*" verbs="OPTIONS, PROPFIND, HEAD"/> </authorization> 
+54
Jan 05 '10 at 17:54
source share

We had a similar problem, but it turned out that this is due to the fact that the user sent to the controller after his login was exhausted. The system is then redirected to the login screen. After logging in, it is redirected back to the URL that the user is trying to send, but this time he made a GET request and therefore did not find an action that was marked with the [HttpPost] attribute.

+12
Apr 07 2018-11-11T00:
source share

I have the same problem in asp.net mvc. this error - 404 not found. I solve the 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<PagesController>(); 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(); } 
+7
Jun 08 '10 at 20:01
source share

We had the same problem in our application, and I was able to trace it back to the javascript / jquery problem. We have links in our application defined using Html.ActionLink (), which are later redefined in POSTs by jquery.

First, we defined the link:

 Html.ActionLink("Click Me", "SomeAction", new { id = Model.Id}) 

Later we will override the default action using our SomePostEventHandler function:

  $(document).ready(function() { $('#MyLink').click(SomePostEventHandler); } 

This influenced our MVC action with the HttpPost filter:

  [HttpPost] public ActionResult SomeAction(int id) { //Stuff } 

We found that most of the time this worked fine. However, on some slow page loads (or really fast users), the user clicked the link before the jquery $ (document) .ready () event was fired, which means they tried GET / Controller / SomeAction / XX instead of posting.

We do not want the user to receive this URL, so removing the filter is not an option for us. Instead, we simply linked the onclick event of the action link directly (we had to modify SomePostEventHandler () a bit to make this work):

 string clickEvent = "return SomePostEventHandler(this);"; Html.ActionLink("Click Me", "SomeAction", new { id = Model.Id}, new { onclick = clickEvent }) 

So, the moral of this story, at least for us, is that if you see these errors, keep track of the URL where you THINK YOU ARE LOST, and make sure you are.

+6
Oct 29 2018-10-29
source share

I also had this problem.

In my case, this was due to the limitations of the verb on the requested action, where the view was POST , but a partial view was requested only in the supported GET and HEAD . Adding the POST verb to AcceptVerbsAttribute (in MVC 1.0) resolved the issue.

+2
Sep 19 '11 at 16:12
source share

I have a similar problem with qq File Download

When the action is post /Document/Save , I get an exception. The public save action method was not found on the Project.Controllers.DocumentController controller.

But if the post-action /Document/Save/ , the message is correct and works!

God save / ?

+1
May 30 '11 at 15:37
source share

From IIS logs, our problem was caused by the attempt by Googlebot POST and GET to only act on the POST controller.

In this case, I recommend processing 404, as Dmitry’s proposal.

+1
Sep 26 '13 at 22:49
source share

Must not be

 routes.MapRoute( "SchoonForm", "Form/Fill/{subscriberId}", new { controller = "Chris", action = "Fill" }, 

Also, what are your filters doing? Can't they hide an action like ActionMethodSelectorAttribute?

0
Nov 16 '09 at 10:16
source share

My root cause was similar to the one mentioned in the commentary.

I clicked the ajaxSubmitting button. One of the form fields was of type Date . However, due to differences in date formats between the client and server machines, he did not execute the POST method on the controller. The server sent a 302 response, and then again sent a GET request for the same method.

However, the action in the controller was decorated with the HttpPost attribute, and therefore, he could not find the method and sent a 404 response.

I just fixed the code so that the mismatch in the Date formats did not cause an error, and the problem was fixed.

0
Jun 27 '13 at 9:24
source share

Remove the [HttpGet] attributes and it will work :)

0
Jan 12 '15 at 12:52
source share

The currently accepted answer works as expected, but is not the primary use case for this feature. Instead, use a function defined by ASP.NET. In my case, I denied everything except GET and POST:

  <system.webServer> <security> <requestFiltering> <verbs allowUnlisted="false"> <add verb="GET" allowed="true"/> <add verb="POST" allowed="true"/> </verbs> </requestFiltering> </security> </system.webServer> 

With the above code snippet, MVC will correctly return 404

0
Jul 24 '15 at 22:57
source share

For those who have this problem with the angularjs, MVC and {{imagepath}} parameters, they are inserted into the src attributes of the image, for example:

"Public action method {{imagepath}} previous.png not found on the controller

The solution is to use ng-src instead of src.

Hope this helps someone :)

0
Aug 17 '16 at 1:01
source share



All Articles