我看到很多以下错误,我认为这取决于对动作方法的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状态代码中看到相同的错误。
有人有什么想法可能导致这个问题吗?
更新以包含Controller继承(为简单起见,删除了很多):
... myController的
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;
}
}