Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.NET Web API-405-不允许使用HTTP谓词访问此页面-如何设置处理程序映射_Asp.net_Asp.net Mvc_Iis_Iis 7_Asp.net Web Api - Fatal编程技术网

Asp.NET Web API-405-不允许使用HTTP谓词访问此页面-如何设置处理程序映射

Asp.NET Web API-405-不允许使用HTTP谓词访问此页面-如何设置处理程序映射,asp.net,asp.net-mvc,iis,iis-7,asp.net-web-api,Asp.net,Asp.net Mvc,Iis,Iis 7,Asp.net Web Api,我使用ASP.NETWebAPI编写了REST服务。 我正在尝试发送HttpDelete请求,但出现以下错误: 405-不允许使用HTTP谓词访问此页 我想我已经接近解决方案了,我发现我应该启用IIS远程管理,转到处理程序映射部分并将删除谓词添加到适当的位置。。。 但问题是名单上有很多不同的位置。。。 (像这里这样的东西:) 我应该编辑哪一个? 它们中很少有没有扩展,例如“ExtensionUrlHandler-Integrated-4.0”,我在其中添加了DELETE动词,但它仍然不起作用 这

我使用ASP.NETWebAPI编写了REST服务。 我正在尝试发送HttpDelete请求,但出现以下错误:

405-不允许使用HTTP谓词访问此页

我想我已经接近解决方案了,我发现我应该启用IIS远程管理,转到处理程序映射部分并将删除谓词添加到适当的位置。。。 但问题是名单上有很多不同的位置。。。 (像这里这样的东西:)

我应该编辑哪一个? 它们中很少有没有扩展,例如“ExtensionUrlHandler-Integrated-4.0”,我在其中添加了DELETE动词,但它仍然不起作用

这只是黑暗中的一个镜头,所以我应该修改不同的位置吗?如果是,哪一个?或者我还应该做些什么

同样的web服务在我的本地服务上工作得非常好,所以我想问题出在远程IIS上


问候语此错误的常见原因是。确保卸载它。

您不需要卸载WebDAV,只需将以下行添加到web.config:

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

不常见,但可能对某些人有所帮助

确保您正在使用来自System.Web.Http的[HttpPut]

我们得到了一个“不允许的方法”405,关于一个HttpPut去编排方法

我们的问题似乎并不常见,因为我们意外地使用了System.Web.Mvc中的[HttpPut]属性,而不是System.Web.Http


原因是,resharper建议使用.Mvc版本,当您直接从ApiController派生时,通常会引用System.Web.Http。我们使用的类扩展了ApiController。

如下更改您的Web.Config文件。它会表现得很有魅力

在节点
中,添加代码的以下部分

<modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule"/>
</modules>

添加后,您的Web.Config如下所示

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="WebDAVModule"/>
    </modules>
    <httpProtocol>
    <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
    </customHeaders>
    </httpProtocol>
    <handlers>
      <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>


如下更改您的Web.Config文件

 <system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV"/>
<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" />
</handlers>
</system.webServer>

如果上述解决方案中没有一个像我的情况那样解决了您的问题(我的RestClient模块仍然面向405),请尝试使用Postman或Fiddler之类的工具请求您的Api。我的意思是,问题可能在其他地方,比如格式错误的请求

我发现我的RestClient模块请求一个Id参数格式不正确的“Put”:

http://myserver/api/someresource?id=75fd954d-d984-4a31-82fc-8132e1644f78
而不是

http://myserver/api/someresource/75fd954d-d984-4a31-82fc-8132e1644f78

顺便说一句,格式错误的请求返回405-不允许使用方法(IIS 7.5)

在我们的例子中,问题在于.Net站点和ADFS之间的联合登录。当重定向到ADFS端点时,
wctx
参数需要该端点的所有三个参数
WSFederationAuthenticationModule.CreateSignInRequest
方法:
rm
id
ru

感谢Guillaume Raymond提供的检查URL参数的提示

当我调用的web api post方法具有参数的基元类型,而不是从主体访问的复杂类型时,就发生了这种情况(不允许使用405方法)。像这样:

这起到了作用:

 [Route("update"), Authorize, HttpPost]
  public int Update([FromBody] updateObject update)
这并没有:

 [Route("update"), Authorize, HttpPost]
 public int Update(string whatever, int whatever, string whatever)

除上述所有解决方案外,请检查“
id
”或
DELETE
方法中的任何自定义参数是否与路由配置匹配

public void Delete(int id)
{
    //some code here
}
如果重复出现405个错误,最好如上所述将方法签名重置为默认值,然后重试

默认情况下,路由配置将在URL中查找
id
。因此,参数名
id
在这里很重要,除非您更改
App\u Start
文件夹下的路由配置

不过,您可以更改
id
的数据类型

例如,下面的方法应该可以很好地工作:

public void Delete(string id)
{
    //some code here
}
注意:还要确保通过url传递数据,而不是将有效负载作为正文内容传递的数据方法

DELETE http://{url}/{action}/{id}
例如:

DELETE http://localhost/item/1

希望有帮助。

此错误来自staticfile处理程序——默认情况下,它不会过滤任何动词,但可能只能处理HEAD和GET

这是因为没有其他处理者走到盘子前说他们可以处理删除

由于您使用的是WEBAPI,由于路由原因,它没有文件,因此没有扩展名,因此需要向web.config文件中添加以下内容:

<system.webserver>
    <httpProtocol>
        <handlers>
          ...
            <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="C:\windows\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="C:\windows\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" />

...
显然,需要什么取决于classicmode与integratedmode,classicmode取决于比特数。此外,还添加了用于CORS处理的选项标题,但如果不执行CORS,则不需要该标题


仅供参考,您的web.config是顶级为applicationHost.config的应用程序(或应用程序目录)版本的本地版本

如果是IIS 8.0,请检查是否启用了HTTP激活。
服务器管理器->IIS->管理(请参见右上方)->添加角色和功能->…->进入WCF配置,然后选择HTTP激活。

我将为那些在尝试运行
PHP
Laravel
,在可能的情况下)或其他独特的
IIS
托管情况下出现
405错误的人添加,您需要更改处理程序中针对特定情况的
动词
。。。因此,由于我使用的是
PHP
,因此我转到
PHP
处理程序,在
请求限制
中,然后在
动词
选项卡中添加所需的
动词。这就是我需要添加到
web.config
的所有内容,以便在
Laravel
中启用
CORS

<handlers>
  <remove name="php-5.6.40" />
  <add name="php-5.6.40" path="*.php" verb="GET,HEAD,POST,PUT,DELETE,OPTIONS" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.6\php-cgi.exe" resourceType="Either" requireAccess="Script" />
</handlers>

我遇到了这个问题,我解决了以下问题:

  • 开放IIS
  • 选择后端站点

  • 在功能视图中:打开处理程序
    <add name="xamlx-ISAPI-4.0_64bit" path="*.xamlx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
    <add name="xamlx-ISAPI-4.0_32bit" path="*.xamlx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
    <add name="xamlx-Integrated-4.0" path="*.xamlx" verb="GET,HEAD,POST,DEBUG" type="System.Xaml.Hosting.XamlHttpHandlerFactory, System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="rules-ISAPI-4.0_64bit" path="*.rules" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
    <add name="rules-ISAPI-4.0_32bit" path="*.rules" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
    <add name="rules-Integrated-4.0" path="*.rules" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="xoml-ISAPI-4.0_64bit" path="*.xoml" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
    <add name="xoml-ISAPI-4.0_32bit" path="*.xoml" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
    <add name="xoml-Integrated-4.0" path="*.xoml" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="svc-ISAPI-4.0_64bit" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
    <add name="svc-ISAPI-4.0_32bit" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
    <add name="svc-Integrated-4.0" path="*.svc" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="rules-64-ISAPI-2.0" path="*.rules" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
    <add name="rules-ISAPI-2.0" path="*.rules" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
    <add name="rules-Integrated" path="*.rules" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode,runtimeVersionv2.0" />
    <add name="xoml-64-ISAPI-2.0" path="*.xoml" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
    <add name="xoml-ISAPI-2.0" path="*.xoml" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
    <add name="xoml-Integrated" path="*.xoml" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode,runtimeVersionv2.0" />
    <add name="svc-ISAPI-2.0-64" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
    <add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
    <add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode,runtimeVersionv2.0" />
    
    <modules>        
            <remove name="WebDAVModule" />    
        </modules> 
          <handlers>
                    <remove name="WebDAV" />
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
          </handlers>