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

Solution 1:

We found the answer. We looked into our web logs. It showed that we were receiving some weird http actions (verbs/methods) like OPTIONS, PROPFIND and HEAD.

This seems to the cause of some of theses exceptions. This explains why it was intermittent.

We reproduced the issue with 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>

Solution 2:

We had a similar issue, but found that it was happening because a user was posting to a controller after his login had timed out. The system then redirected to the login screen. After logging in it redirected back to the URL the user was trying to post to, but this time it was doing a GET request instead and therefore not finding the action which was marked with an [HttpPost] attribute.

Solution 3:

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<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();
    }

Solution 4:

We just had the same issue on our application and I was able to trace it to a javascript/jquery issue. We have links in our application defined using Html.ActionLink() that are later overridden into POSTs by jquery.

First we had defined the link:

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

Later we override the default action with our SomePostEventHandler function:

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

This was hitting our MVC action that had a HttpPost filter:

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

What we found is that most of the time this worked great. However, on some slow page loads (or really fast users), the user was clicking the link before the jquery $(document).ready() event was firing, meaning that they were trying to GET /Controller/SomeAction/XX instead of posting.

We don't want the user to GET that url, so removing the filter is not an option for us. Instead we just wired the onclick event of the action link directly (we had to change SomePostEventHandler() slightly for this to work):

string clickEvent = "return SomePostEventHandler(this);";

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

So, moral of the story, for us at least, is that if you are seeing these errors, track down the URL that you THINK you are POSTing to and make sure you are.

Solution 5:

I too had this issue.

In my case it was related to verb restrictions on the requested action, where the view was a POST but the partial view being requested within supported GET and HEAD only. Adding the POST verb to the AcceptVerbsAttribute (in MVC 1.0) resolved the problem.