Can't PUT to my IHttpHandler, GET works fine

為{幸葍}努か 提交于 2019-12-23 02:01:31

问题


I'm in the process of writing an IHttpHandler. My environment is Windows 7 Enterprise, IIS 7 (it appears). My handler is running as an application under the default app pool which is running in integrated mode.

Currently my handler's ProcessRequest() method only does the following (just testing at this point):

public void ProcessRequest(HttpContext context)
{
    context.Response.StatusCode = 200;
    context.Response.ContentType = "text/html";
    context.Response.Output.Write("file uploaded.");
}

I add my handler via the web.config as follows:

<configuration>
    <system.webServer>
        <handlers>
            <add name="HttpUpload" path="*" verb="*" type="HttpUpload, HttpUpload" resourceType="Unspecified"/>
        </handlers>
    </system.webServer>
</configuration>

I'm using curl to test my handler. When I do the following:

curl http://localhost/httpupload/foo

It works. However, when I attempt to do a PUT as follows:

curl --upload-file build.txt http://localhost/httpupload/foo

It fails with a 405, Method Not Allowed, error. I searched around and others on stackoverflow indicated that WebDAVModule needs to be removed. I removed that and it did resolve the 405 error. However, now I'm getting a 500.21 error. From the failed request tracing it's saying the 'IIS Web Core' module is generating the 500.21 error because 'The data is invalid.' (8007000d). The issue seems similar to this post:

IIS 7, HttpHandler and HTTP Error 500.21

Yet what seemed to fix it for others, eg running aspnet_regiis -i, had no impact for me. I debugged my handler and it breaks on my handler's ProcessRequest() method when using GET but it doesn't break on it when using PUT thus I know it's not even getting called. For some reason this other core module is failing the call.

EDIT:

I executed a curl command against the same URL which does a POST and that worked. So GET and POST work against my http handler, PUT doesn't. I also executed the same --upload-file curl command to a URL on the same box backed by WebDAV and that worked.

Thanks, Nick


回答1:


Well I continued to search around and while looking at the docs for the configuration I saw the following:

runManagedModulesForWebDavRequests

when reading the following documentation:

https://www.iis.net/configreference/system.webserver/modules

I set it to true

<modules runManagedModulesForWebDavRequests="true">

and voila, PUT now works for my http handler. I guess once you install WebDAV then all PUT's are associated with WebDAV? I don't know, but it appears that way. So it looks like if you have WebDAV installed you need to disable it and then set this flag to true.



来源:https://stackoverflow.com/questions/33285257/cant-put-to-my-ihttphandler-get-works-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!