ASP.Net的WebAPI删除动词不工作 [英] ASP.Net WebAPI Delete verb not working

查看:223
本文介绍了ASP.Net的WebAPI删除动词不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是IIS 7.5 asp.net的WebAPI做了记录ID删除。我可以得到它在Safari工作,但不是Firefox浏览器。下面是jQuery的阿贾克斯提交请求/响应的图像:

I'm using IIS 7.5 with asp.net webapi to do a delete for a record id. I can get it to work in Safari, but not Firefox. Here's an image of the request/response for the jQuery Ajax submission:

http://screencast.com/t/Ckls9nO8D

下面是我的$我的jQuery提交删除C $Ç片段:

Here's my code snippet for my jQuery Delete submission:

    var deleteGame = function(gameId)
    {       
        var d = $.Deferred();
        var url = Enum.RootUrl + Enum.DeleteGameUrl + gameId;
        jQuery.support.cors = true;
        $.ajax(
        {
            url: url,
            type: 'Delete',
            cache: false,
            crossDomain: true,
            processData: true,
            success: function () 
            {
                d.resolve();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown)
            {
                //alert("error happened AGAIN:\n" + JSON.stringify(XMLHttpRequest) );
            }
        });

        return d.promise();
    };

这里是jQuery的提交生成的URL: http://local.guessalist.com/api/游戏/ 46

我不知道为什么它工作在Safari但不是Firefox浏览器。请帮助。

I'm not sure why it works in Safari but not Firefox. Please help.

这似乎访问控制请求报头从请求头缺失。我不知道这是否是问题的原因。

It appears Access-Control-Request-Headers is missing from Request Headers. I'm not sure if this is the cause of the problem.

在Safari和Chrome这个玩弄之后,我越来越为由,拒绝不安全设置页眉访问​​控制请求报头
OPTIONS http://local.guessalist.com/api/game/64 405(方法不允许)的错误在通过浏览器的控制台每个浏览器,但允许删除操作继续进行。不知道我在做什么在这里。任何意见将是极大的AP preciated。

After playing around with this in Safari and Chrome, I'm getting "Refused to set unsafe header "Access-Control-Request-Headers" OPTIONS http://local.guessalist.com/api/game/64 405 (Method Not Allowed)" error in each browser via the browser's console, but the delete operation is allowed to continue. Not sure what I'm doing here. Any advice would be greatly appreciated.

推荐答案

几个小时研究,解决问题,咒骂,和翻转了我的code之后,我终于明白了这种方法的帮助下工作:

After several hours of researching, trouble shooting, cursing, and flipping off my code, I finally got it working with the help of this approach:

<一个href=\"http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/\" rel=\"nofollow\">http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/

我最初试图刚的WebAPI的做法,并没有奏效。然后我删除一切,我是想和遵循上面的链接描述的IIS的做法,一切正常。我不知道为什么。我只加这行code的到Web.config中,没有别的:

I initially tried just the WebAPI approach, and it didn't work. I then removed everything I was trying and followed the IIS approach described in the link above, and everything works. I'm not sure why. I only added this line of code to Web.Config and nothing else:

    <modules runAllManagedModulesForAllRequests="true">
        <add name="CorsHttpModule" type="Thinktecture.IdentityModel.Http.Cors.IIS.CorsHttpModule"/>
    </modules>

这是我做了唯一的配置,我可以做跨域删除。我假设其他动词都可以工作,我只用Delete(删除)进行测试。所以,我很感激,我可以让我的code的工作,但我不知道为什么它的工作给出的链接引用上面我只是做配置的一部分。如果有人绊倒在这一点,并可以解释,我就AP preciate它。谢谢你。

That's the only configuration I did and I can do cross domain deletes. I'm assuming other verbs will work, I've only tested with Delete. So, I'm grateful that I can get my code to work, but am wondering why it's working given that I only did part of the configuration as cited in the link above. If anyone stumbles upon this and can explain, I would appreciate it. Thanks.

这篇关于ASP.Net的WebAPI删除动词不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆