Occasionally when hitting a POST action method I'll get this exception:
Error Message:
(System.Web.HttpException): No matching action was found on controller 'xyz'. This can happen when a controller uses RouteAttribute for routing, but no action on that controller matches the request.
The action methods, as a rule, look like this:
[Authorize(Roles = "RoleOfSomeSort")]
[HttpPost]
[Route("path-1/path-2")]
[ValidateAntiForgeryToken]
public ActionResult MethodName(ViewModel viewModel)
{
// Code
}
If I try again it will usually work. It's just an exception that pops up occasionally and then vanishes when I try to replicate it.
I'm testing the website in Azure Web Apps. I'm pretty sure I never got this error on my development machine. This error has happened in both Free and Shared mode.
Stack trace:
at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Let me know if you want any more information.
EDIT:
Request URLs that threw this exception:
/list/create-job-vacancy-listing
/list/create-services-labour-hire-listing
/my-stuff/my-listings/upload-photo
Digging into the ASP.NET MVC code here: https://github.com/ASP-NET-MVC/aspnetwebstack/blob/4e40cdef9c8a8226685f95ef03b746bc8322aa92/src/System.Web.Mvc/Controller.cs, here is the line that is failing (line 304):
protected virtual void HandleUnknownAction(string actionName)
{
// If this is a direct route we might not yet have an action name
if (String.IsNullOrEmpty(actionName))
{
throw new HttpException(404, String.Format(CultureInfo.CurrentCulture,
MvcResources.Controller_UnknownAction_NoActionName, GetType().FullName));
}
So actionName is null or empty. Because of all the asynchronous stuff I'm not sure why this occasionally happens. Maybe it happens because of the asynchronicity? It's very rare but very annoying. Thanks.