1

Maday,我在 db 中记录了这个错误,有任何想法或线索来修复这个间歇性的 asp.net mvc 异常。谢谢

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)
4

2 回答 2

1

我不能肯定地说,但我怀疑这是在 JavaScript 中构建的 URL 的结果,其中没有定义变量。

就像是:

var action
var url = '/myContoller/' + action

这将导致请求:

/myContoller/未定义

预期的 URL 可能用于甚至不打算成为 MVC 路由的东西。它可能是图像或其他东西。

var imageUrl
var url = '/folder/' + imageUrl

/myFolder/未定义

MVC 将尝试路由该路由,具体取决于您的路由配置方式。

您的日志中是否有任何关于请求来自何处的信息?

更新1:

如果您希望 MVC 忽略对站点特定区域(例如图像目录)的所有请求,您可以执行以下操作:

routes.IgnoreRoute("images/{*pathinfo}");
于 2013-08-28T13:39:47.307 回答
0


根据@Dan 的有用回答,我发现了一种解决图像 URL 路由问题的可能方法:


所以,因为我在我的 404 错误中有这个“包罗万象”的路线RouteConfig.cs

// for 404-error page routing
routes.MapRoute(
    name: "Error",
    url: "{*url}",
    defaults: new { controller = "Error", action = "PageNotFound" }
);


...MVC 奇怪地将我通过 Razor@foreach语句加载的图像解释为 URL:

// 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" />
}


异常类型为HttpException,生成的异常消息为:

在控制器“MyWebsite.Controllers.HomeController”上找不到公共操作方法“[object HTMLImageElement]”



放置在我的方法routes.IgnoreRoute("MyImageFolderPath/{*pathinfo}");的顶部并没有解决这个问题,但是这样做了:RegisterRoutesRouteConfig.cs

routes.IgnoreRoute("[object HTMLImageElement]");


尽管如此,它仍然看起来很老套,而且由于我处理 404 错误的执行不力...... 您可以

通过在RouteConfig.cs整个. Application_ErrorGlobal.asax.csHttpException

于 2014-01-14T07:39:39.983 回答