我看到很多以下错误,我认为这是对操作方法的 HEAD 请求(可能来自机器人):
A public action method 'index' was not found on controller 'MyWebsite.MyController'.
at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
at EPiServer.Web.Mvc.ActionControllerBase.HandleUnknownAction(String actionName)
at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyn cResult asyncResult)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyn cResult asyncResult)
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyn cResult asyncResult)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.I ExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我的操作方法最初仅设置为接受 GET 请求,但我现在已将其更改为也接受 HEAD 请求,例如:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
public async override Task<ActionResult> Index()
{
....
return View(new Model());
}
但是,当我测试页面的 HEAD 请求时,我在响应中看到相同的错误和 404 状态代码。
请问有人知道是什么原因造成的吗?
更新以包括控制器继承(为简单起见删除了很多):
我的控制器...
public class MyController: BasicContentPageController<MyPageType>
{
public MyController(IPageUrlProvider pageUrlProvider)
: base(pageUrlProvider)
{
}
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
public async override Task<ActionResult> Index()
{
...
return View(new Model());
}
}
...从 BasicContentPageController 继承...
public abstract class BasicContentPageController<T> : MyBasePageContoller<T> where T : MyBasePageType
{
protected BasicContentPageController(IPageUrlProvider pageUrlProvider)
: base(pageUrlProvider)
{
}
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
public virtual async Task<ActionResult> Index()
{
return View(await GetBasicPageViewModel());
}
}
...从 MyBasePageController 继承...
public abstract class MyBasePageContoller<T> : PageController<T>
where T : MyBasePageType
{
protected readonly IPageUrlProvider PageUrls;
protected MyBasePageContoller(IPageUrlProvider pageUrlProvider)
{
PageUrls = pageUrlProvider;
}
}