JSON WebMethod 无法在 Sitefinity 中工作
我试图通过 ajax 调用托管在传统 ASP.Net WebForm 代码隐藏页面中的 WebMethod。 下面是 WebMethod 的代码:
[WebMethod]
public static object States()
{
StateProvince[] states = new StateProvince[] { };
ApplicationServiceClient proxy = null;
try
{
proxy = new ApplicationServiceClient();
states = proxy.GetStateProvinces();
}
finally
{
CloseServiceProxy(proxy);
}
return states;
}
WebMethod 在我的独立开发环境中或者正常部署到 IIS 中工作得很好,但是当我将 aspx 页面部署到 Sitefinity 时,在调用它时会出现以下异常:
Server “/”应用程序出错。
未知的 Web 方法 States.aspx。
参数名称:methodName
我不确定 Sitefinity 是否劫持了 URL 并后置“.aspx”或这里发生了什么。
以下是调用 Web 方法的 jquery 调用:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Regions.aspx/States",
data: "{}",
success: function(data) {
// implementation omitted
},
error: function(xhr, msg) {
alert(xhr.responseText);
}
});
我可以通过使用 Fiddler 手动发布请求来复制该问题。
同样,除了部署到 Sitefinity 时之外,这在任何地方都可以正常工作。 有人有什么想法吗?
I am trying to call via ajax a WebMethod hosted in a traditional ASP.Net WebForm code-behind page. Here is the code for the WebMethod:
[WebMethod]
public static object States()
{
StateProvince[] states = new StateProvince[] { };
ApplicationServiceClient proxy = null;
try
{
proxy = new ApplicationServiceClient();
states = proxy.GetStateProvinces();
}
finally
{
CloseServiceProxy(proxy);
}
return states;
}
The WebMethod works just fine in my stand-alone development environment or if deployed normally to IIS, but when I deploy the aspx page to Sitefinity, I get the following exception when it's called:
Server Error in '/' Application.
Unknown web method States.aspx.
Parameter name: methodName
I'm not sure if Sitefinity is hijacking the URL and post-pending the ".aspx" or what is going on here.
Here is the jquery call that is calling the web method:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Regions.aspx/States",
data: "{}",
success: function(data) {
// implementation omitted
},
error: function(xhr, msg) {
alert(xhr.responseText);
}
});
I can replicate the problem by posting the request manually using Fiddler.
Again, this works just fine everywhere except when deployed to Sitefinity. Anybody have any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sitefinity 运行的是哪个版本的 .NET? 页面方法是最近添加的。
What version of .NET is Sitefinity running? Page methods are a recent addition.
使用数据类型:“json”,
use dataType: "json",