AJAX Webmethod 调用在 MVC3 上返回 404

2024-05-04

我一直在使用 EXTJS 4 并通过 AJAX 调用 .aspx 页面代码隐藏上的 Webmethod 来加载我的商店。此方法适用于我的所有项目,直到我尝试将 EXTJS 4 工作移植到 MVC3 项目中。我的电话现在返回 404。

关键部分是该项目(和 EXTJS4 webmethod 调用)可以在我同事的机器上运行 - 只有我的机器受到此“404”错误的影响。任何 Webmethod 调用,无论是他们的还是我编写的,都会返回“找不到资源”。这是怎么回事?

一些代码(如果有帮助的话): 加载商店:

Ext.define('pr.store.Store-Items', {
    extend: 'Ext.data.Store',
    model: 'pr.model.Model-Items',
    pageSize: 200,
    groupField: 'groupID',
    autoLoad: { params: { start: 0, limit: 200 } },
    proxy: {
        type: 'ajax',
        //get data from json file for now
        headers: { 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Content-Type': 'application/json; charset=utf-8' },
        url: '/Project/Data.ashx/GetData',           
        reader: {
            type: 'json',
            root: 'd.objects',
            totalProperty: 'd.totalCount'
        },
        extraParams: {
            where: Ext.encode(new Array(''))
            , difference: true
            , mode: 0
        }
    }
});

网络方法

 [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json, UseHttpGet=true)]
 [System.Web.Services.WebMethod]
 public static object GetData(int start, int limit, string[] where, bool difference, int mode)
 {
     //Code
 }

我还遇到了这个问题,因此从 Web.Config 中删除了以下内容。

<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

在 system.webServer > 处理程序中找到。


此外,我们还在 Global.asax.cs 文件中添加了以下 3 条规则:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AJAX Webmethod 调用在 MVC3 上返回 404 的相关文章

随机推荐