gpt4 book ai didi

asp.net-mvc - 间歇性的asp.net mvc异常: “A public action method ABC could not be found on controller XYZ.”

转载 作者:行者123 更新时间:2023-12-03 05:02:10 28 4
gpt4 key购买 nike

我收到间歇性异常,提示 asp.net mvc 找不到操作方法。异常(exception)情况如下:

A public action method 'Fill' could not be found on controller 'Schoon.Form.Web.Controllers.ChrisController'.

我认为我的路由设置正确,因为此应用程序大部分时间都可以工作。这是 Controller 的操作方法。

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

路线:

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

这是堆栈:

System.Web.HttpException: A public action method 'Fill' could not be found on controller 'Schoon.Form.Web.Controllers.ChrisController'. at System.Web.Mvc.Controller.HandleUnknownAction(String actionName) in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\Controller.cs:line 197 at System.Web.Mvc.Controller.ExecuteCore() in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\Controller.cs:line 164 at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\ControllerBase.cs:line 76 at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\ControllerBase.cs:line 87 at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\MvcHandler.cs:line 80 at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\MvcHandler.cs:line 68 at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) in C:\dev\ThirdParty\MvcDev\src\SystemWebMvc\Mvc\MvcHandler.cs:line 104 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

这是我的过滤器的示例,它们的工作方式都相同:

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

谢谢,克里斯

最佳答案

我们找到了答案。我们查看了我们的网络日志。它表明我们收到了一些奇怪的 http 操作(动词/方法),例如 OPTIONS、PROPFIND 和 HEAD。

这似乎是其中一些异常的原因。这解释了为什么它是间歇性的。

我们使用curl.exe工具重现了该问题:

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

我们使用的修复方法是向 web.config 添加授权部分:

<authorization>
<deny users="*" verbs="OPTIONS, PROPFIND, HEAD"/>
</authorization>

关于asp.net-mvc - 间歇性的asp.net mvc异常: “A public action method ABC could not be found on controller XYZ.” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1745182/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com