Asp.net mvc 通过Ajax调用Sitecore ItemWebApi时出现404错误
我试图按照本视频中的教程进行操作: 还有这个博客: 这些教程的示例都启动了对urlAsp.net mvc 通过Ajax调用Sitecore ItemWebApi时出现404错误,asp.net-mvc,sitecore,Asp.net Mvc,Sitecore,我试图按照本视频中的教程进行操作: 还有这个博客: 这些教程的示例都启动了对url/api/sitecore/{controller}/{action}的ajax调用。它重定向到控制器操作是默认的Sitecore行为,还是我需要自己配置路由?我无法使此url按教程所示工作。每次都是404错误。我正在使用Sitecore 8 谢谢 编辑: 下面是我的控制器类中的代码 using System; using System.Collections.Generic; using System.Linq
/api/sitecore/{controller}/{action}
的ajax调用。它重定向到控制器操作是默认的Sitecore行为,还是我需要自己配置路由?我无法使此url按教程所示工作。每次都是404错误。我正在使用Sitecore 8
谢谢
编辑:
下面是我的控制器类中的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SwireCitygate.Web.Controllers
{
public class MembersBehaviourReportsController : Controller
{
// GET: Default
public ActionResult GetText()
{
string text = "Hello World";
return Json(text, JsonRequestBehavior.AllowGet);
}
}
}
它继承了System.Web.Mvc.Controller
和JS文件:
define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
initialize: function (options) {
this._super();
this.set("output", null);
this.GetText(this);
},
GetText: function (app) {
jQuery.ajax({
type: "GET",
dataType: "json",
url: "/api/sitecore/MembersBehaviourReports/GetText",
cache: false,
success: function (data) {
app.set("output", data);
},
error: function () {
console.log("There was an error in GetText() function!");
}
});
}
});
var view = Sitecore.Definitions.Views.ControlView.extend({
initialize: function (options) {
this._super();
this.set("output", null);
}
});
Sitecore.Factories.createComponent("MembersBehaviourReportsDataSource", model, view, ".sc-MembersBehaviourReportsDataSource");
});
如果没有看到您的代码,我会说您应该确保您的控制器继承自MVC控制器
System.Web.Controller
,而不是WebApi控制器System.Web.Http.ApiController
如果您使用的是WebApi控制器,则需要设置自定义路由,而不是使用/api/sitecore/…毕竟,问题是由sitecore配置引起的。未启用ItemWebAPI
<site name="website">
<patch:attribute name="itemwebapi.mode">Off</patch:attribute>
<patch:attribute name="itemwebapi.access">ReadOnly</patch:attribute>
<patch:attribute name="itemwebapi.allowanonymousaccess">false</patch:attribute>
</site>
关
只读
假的
我将itemwebapi.mode设置为StandardSecurity,将itemwebapi.allowanonymousaccess设置为true,然后它神奇地工作了。您使用的url是什么?你不应该在他们的url中使用word controller,例如,如果你有
MyCustomController
类,你应该使用/api/sitecore/mycustom/someaction
。我完全使用/api/sitecore/mycustom/someaction
,但它就是不起作用。你能发布你的代码吗?代码片段添加到原始问题中