Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

c# - How do I enable HTTP PUT and DELETE for ASP.NET MVC in IIS?

I use HTTP PUT and DELETE in my ASP.NET MVC3 application. When I run it in local, every thing works correctly; But when I publish the application to the server, these methods do not work.

Are there any special settings for enable a web server to support PUT and DELETE requests? I'm using shared hosting with IIS 7.5.

UPDATE:

I enable PUT and DELETE requests in IIS manager. PUT command work fine. But DELETE still not works. I create requests by jQuery:

I'm in this page:

http://domain.com/dashboard/edit-site/103323/links/

and my ajax call is:

$.ajax({
    // url: same as page-url,
    cache: false,
    type: 'DELETE',
    data: { linkid: $(link).data("linkid") },
    beforeSend: function () {
        // doing something in UI
    },
    complete: function () {
        // doing something in UI
    },
    success: function (data) {
        // doing something in UI
    },
    error: function () {
        // doing something in UI
    }
});

This will create a request like this:

Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://domain.com
Referer: http://domain.com/dashboard/edit-site/103323/links/
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
X-Requested-With: XMLHttpRequest

With this Form Data:

linkid:104044
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Go to Handler Mappings in your IIS Manager. Find ExtensionlessUrlHandler-Integrated-4.0, double click it. Click Request Restrictions... button and on Verbs tab, add both DELETE and PUT. enter image description here


EDIT: Possible WebDav Publisher issue

You've mention on a deleted post you were running on a 2008 server right? Try removing webDav role, or disable it from your site config: on system.webServer -> modules section, remove WebDAVModule module:

<system.webServer>
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webServer>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...