WebAPI DELETE请求在Azure中返回404错误

时间:2013-04-12 06:44:31

标签: azure asp.net-web-api iis-8

我一直在尝试在我的ASP.net WebAPI(ASP.net Web角色)中使用Azure上的本地机器上的DELETE请求。但最终得到“未找到”错误。

我对ASP.net WebAPI Web角色的web.config进行了以下配置:

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
   <remove name="WebDAV" />
   <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
   <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
   <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
   <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"
     path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
     modules="IsapiModule"
     scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
     preCondition="classicMode,runtimeVersionv4.0,bitness32"
     responseBufferLimit="0" />
   <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"
     path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
     modules="IsapiModule"
     scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
     preCondition="classicMode,runtimeVersionv4.0,bitness64"
     responseBufferLimit="0" />
   <add name="ExtensionlessUrlHandler-Integrated-4.0"
     path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
     type="System.Web.Handlers.TransferRequestHandler"
     preCondition="integratedMode,runtimeVersionv4.0" />
 </handlers>
</system.webServer>

为了使它在IISExpress上运行,我更改了$:\ Users \\ Documents \ IISExpress \ config \ applicationhost.config配置并注释掉了它的WebDav部分并适当地添加了“PUT,DELETE”动词。

为了测试我的WebAPI,我创建了一个简单的Windows窗体(.net 4.5)c#应用程序,并使用了httpclient,如下所示:

const string key = "user1";
var client = new HttpClient { BaseAddress = new Uri("http://abcd.cloudapp.net/") };
client.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("application/json"));
var requestUrl = string.Format("api/user/{0}", key);
var deleteAsync = client.DeleteAsync(requestUrl).Result;

我得到的回应如下:

{StatusCode: 404,
  ReasonPhrase: 'Not Found',
  Version: 1.1,
  Content: System.Net.Http.StreamContent,
  Headers:
  {
    Pragma: no-cache
    Cache-Control: no-cache
    Date: Fri, 12 Apr 2013 06:40:31 GMT
    Server: Microsoft-IIS/8.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Content-Length: 128
    Content-Type: application/json; charset=utf-8
    Expires: -1
}}  System.Net.Http.HttpResponseMessage

如何让它在Azure上运行?也可能在我的本地机器上。

0 个答案:

没有答案