网站 Api 使用 Sitecore 8.1

Web Api with Sitecore 8.1

我一直在尝试让 Web Api 与 Sitecore 8.1 一起工作。

我安装了这个包:https://www.nuget.org/packages/Krusen.Sitecore.WebApi.Custom/ 并将 ConfigureWebApi 修改为以下内容:

public class ConfigureWebApi
{
    public void Process(PipelineArgs args)
    {
        GlobalConfiguration.Configure(config => config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",
            new { id = RouteParameter.Optional }));
        GlobalConfiguration.Configure(config => config.MapHttpAttributeRoutes());
        GlobalConfiguration.Configure(ReplaceControllerSelector);
    }

    private static void ReplaceControllerSelector(HttpConfiguration config)
    {
        config.Services.Replace(typeof (IHttpControllerSelector),
            new CustomHttpControllerSelector(config, new NamespaceQualifiedUniqueNameGenerator()));
    }
}

但是,每当我使用 post 请求时,我都会收到以下错误:

{"Message":"The requested resource does not support http method 'POST'."}. Get requests work.

这是控制器的实现:

[RoutePrefix("api/authentication")]
public class AuthenticationController : ApiController
{
    [Route("email")]
    [HttpPost]
    public bool Login([FromBody] string email)
    {
        return true;
    }
}

我知道错误是什么了。当我的控制器被称为 AuthenticationController 时,它给出了以下错误:

The requested document was not found

如果我给它起别的名字,网络 api 就像一个魅力,例如

public TestController : ApiController {
    //Code goes here
}