Reputation: 309
Maday, i'm getting this error logged in db any idea or clue to fix this intermittent asp.net mvc exception. thanks
Unhandled System.Web.HttpException (0x80004005): A public action method 'undefined' was not found on controller '#######'.
at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`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) at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`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)
Upvotes: 1
Views: 6981
Reputation: 2748
I have discerned a possible way to fix the image URL routing problem, based on @Dan's helpful answer:
RouteConfig.cs
:
// for 404-error page routing
routes.MapRoute(
name: "Error",
url: "{*url}",
defaults: new { controller = "Error", action = "PageNotFound" }
);
...MVC is oddly interpreting images that I have loaded via a Razor @foreach
statement as URL's:
// this is triggering the weird problem, dunno why:
@foreach (string image in this.Model.ImageArray)
{
<img src="@this.Url.Content(image)" title="foobar" alt="@image" />
}
The Exception type is HttpException
and the Exception message generated is:
A public action method '[object HTMLImageElement]' was not found on controller 'MyWebsite.Controllers.HomeController'
routes.IgnoreRoute("MyImageFolderPath/{*pathinfo}");
at the top of the RegisterRoutes
method in my RouteConfig.cs
did not resolve this issue, but this did:
routes.IgnoreRoute("[object HTMLImageElement]");
It still seems hackish though, and due to my poor implementation of handling 404-errors...
You can verify that it works though by sprinkling breakpoints throughout your RouteConfig.cs
, and also in the Application_Error
method in Global.asax.cs
(if you are also handling HttpException
errors there).
Upvotes: 0
Reputation: 717
I can't say for sure, but I suspect this is the result of a URL being constructed in JavaScript where a variable is not being defined.
Something like:
var action
var url = '/myContoller/' + action
This will result in a request to:
/myContoller/undefined
The intended URL could be for something that isn't even intended to be an MVC route. It could be for an image or something.
var imageUrl
var url = '/folder/' + imageUrl
/myFolder/undefined
MVC will try to route that, depending on how your routing is configured.
Is there any information in your logs about where the requests are coming from?
Update 1:
If you want MVC to ignore all requests to a particular area of your site (images directory for example), you can do something like this:
routes.IgnoreRoute("images/{*pathinfo}");
Upvotes: 1