JSON WebMethod 无法在 Sitefinity 中工作

发布于 2024-07-18 02:34:17 字数 1171 浏览 7 评论 0原文

我试图通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2024-07-25 02:34:17

Sitefinity 运行的是哪个版本的 .NET? 页面方法是最近添加的。

What version of .NET is Sitefinity running? Page methods are a recent addition.

蓝眼泪 2024-07-25 02:34:17

使用数据类型:“json”,

use dataType: "json",

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文