如何获得PUT和DELETE动词用的WebAPI在IIS工作 [英] How to get PUT and DELETE verbs to work with WebAPI on IIS

查看:561
本文介绍了如何获得PUT和DELETE动词用的WebAPI在IIS工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的WebAPI PUT和DELETE方法来执行使用jQuery通过AJAX从我的网站的行为。我的服务器是Windows Server 2008 R2的使用Plesk安装。 POST和GET请求工作得很好,但PUT和DELETE失败。

我最初得到一个 401未授权响应当我第一次部署我的网站服务器。然后,我进行了一些行动,并将其转化为 405不允许的方法

现在我在一个点,我收到一个内部服务器错误:

  

处理程序ExtensionlessUrlHandler集成-4.0有一个坏模块   在其模块列表ManagedPipelineHandler

现在,有很多关于这个职位的,可悲的是,我不能得到它的工作还没有。

下面是我已经试过:

  • 添加删除标签内的的web.config WebDAV的处理程序和模块
  • 设置权限处理程序映射中执行脚本和可执行文件
  • 添加PUT和POST动词来在IIS中
  • 新增PUT和POST动词的的web.config
  • 下载.NET Framework和执行修复
  • 在这个答案显示重新注册.NET Framework作为
  • 在调查的CORS,但我没有做任何跨站点的脚本,这只是AJAX来自同一个域名为

我怎样才能摆脱这个消息,让我PUT和DELETE工作?

这是我的web.config中

 < XML版本=1.0编码=UTF-8&GT?;
<! - 
  有关如何配置ASP.NET应用程序的更多信息,请访问:
  http://go.microsoft.com/fwlink/?LinkId=169433
   - >
<结构>
  < configSections>
    <! - 有关实​​体框架配置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468  - >
    <节名称=的EntityFrameworkTYPE =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,的EntityFramework,版本= 6.0.0.0,文化=中性公钥= b77a5c561934e089requirePermission =FALSE/>
  < sectionGroup名=ELMAH>
      <节名称=安全requirePermission =假TYPE =Elmah.SecuritySectionHandler,ELMAH/>
      <节名称=错误日志requirePermission =假TYPE =Elmah.ErrorLogSectionHandler,ELMAH/>
      <节名称=errorMailrequirePermission =假TYPE =Elmah.ErrorMailSectionHandler,ELMAH/>
      <节名称=errorFilterrequirePermission =假TYPE =Elmah.ErrorFilterSectionHandler,ELMAH/>
    < / sectionGroup>< / configSections>
  <的EntityFramework>
    < defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlConnectionFactory,的EntityFramework/>
    <供应商>
      <供应商invariantName =MySql.Data.MySqlClientTYPE =MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity.EF6/>
    < /供应商>
  < /的EntityFramework>
  <的ConnectionStrings>< /的ConnectionStrings>
  <的appSettings>
    <添加键=网页:版本值=3.0.0.0/>
    <添加键=网页:启用值=FALSE/>
    <添加键=preserveLoginUrl值=真/>
    <添加键=ClientValidationEnabled值=真/>
    <添加键=UnobtrusiveJavaScriptEnabled值=真/>
    <添加键=owin:AppStartup值=uQuiz.OwinStart/>
    <添加键=elmah.mvc.disableHandler值=FALSE/>
    <添加键=elmah.mvc.disableHandleErrorFilter值=FALSE/>
    <添加键=elmah.mvc.requiresAuthentication值=FALSE/>
    <添加键=elmah.mvc.IgnoreDefaultRoute值=FALSE/>
    <添加键=elmah.mvc.allowedRoles值=*/>
    <添加键=elmah.mvc.allowedUsers值=*/>
    <添加键=elmah.mvc.route值=ELMAH/>
  < /的appSettings>
  <的System.Web>
    <编译targetFramework =4.5/>
    <的httpRuntime targetFramework =4.5/>
    <网页>
      <命名空间>
        <加上命名空间=System.Web.Helpers/>
        <加上命名空间=System.Web.Mvc/>
        <加上命名空间=System.Web.Mvc.Ajax/>
        <加上命名空间=System.Web.Mvc.Html/>
        <加上命名空间=System.Web.Routing/>
        <加上命名空间=System.Web.WebPages/>
      <加上命名空间=Westwind.Utilities/><加上命名空间=Westwind.Web/>< /命名空间>
    < /页>
    <的HttpModules>
      <添加名称=ScriptCom pressionModuleTYPE =Westwind.Web.ScriptCom pressionModule,Westwind.Web/>
      <添加名称=ImageProcessorModuleTYPE =ImageProcessor.Web.HttpModules.ImageProcessingModule,ImageProcessor.Web/>
      <添加名称=错误日志TYPE =Elmah.ErrorLogModule,ELMAH/><添加名称=ErrorMailTYPE =Elmah.ErrorMailModule,ELMAH/>
      <添加名称=ErrorFilterTYPE =Elmah.ErrorFilterModule,ELMAH/>
    < / HttpModules的>
    <的sessionState模式=StateServer的无Cookie =假超时=60stateConnectionString这一=TCPIP =回环:42424stateNetworkTimeout =3600/>
  < /system.web>
  < system.webServer>
    <验证validateIntegratedModeConfiguration =FALSE/>
    <处理器accessPolicy =读取,执行脚本>
      <! - 删除的WebDAV模块做出的WebAPI工作PUT方法 - >
      <删除名称=WebDAV的/>
      <删除名称=ExtensionlessUrlHandler集成-4.0/>
      <删除名称=OPTIONSVerbHandler/>
      <删除名称=TRACEVerbHandler/>
      <添加名称=ExtensionlessUrlHandler集成-4.0路径=*。动词=GET,HEAD,POST,DEBUG,PUT,DELETETYPE =System.Web.Handlers.TransferRequestHandler资源型=未指定requireAccess =执行preCondition =integratedMode,runtimeVersionv4.0/&GT ;
    < /处理器>
    <模块runAllManagedModulesForAllRequests =真正的>
      <删除名称=WebDAVModule/>
      <添加名称=ScriptCom pressionModuleTYPE =Westwind.Web.ScriptCom pressionModule,Westwind.Web/>
      <添加名称=ImageProcessorModuleTYPE =ImageProcessor.Web.HttpModules.ImageProcessingModule,ImageProcessor.Web/><添加名称=错误日志TYPE =Elmah.ErrorLogModule,ELMAHpreCondition =managedHandler /><添加名称=ErrorMailTYPE =Elmah.ErrorMailModule,ELMAHpreCondition =managedHandler/><添加名称=ErrorFilterTYPE =Elmah.ErrorFilterModule,ELMAHpreCondition =managedHandler/>
    < /模块>
  < /system.webServer>
  <运行>
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
      < dependentAssembly>
        < assemblyIdentity名=Newtonsoft.Json文化=中性公钥=30ad4fe6b2a6aeed/>
        < bindingRedirect oldVersion =0.0.0.0-6.0.0.0NEWVERSION =6.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Helpers公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Mvc公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =0.0.0.0-5.2.0.0NEWVERSION =5.2.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Optimization公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0-1.1.0.0NEWVERSION =1.1.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.WebPages公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=WebGrease公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =0.0.0.0-1.5.2.14234NEWVERSION =1.5.2.14234/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=Microsoft.Owin公钥=31bf3856ad364e35文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Http公钥=31bf3856ad364e35文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-5.2.0.0NEWVERSION =5.2.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=Ninject公钥=c7192dc5380945e7文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-3.2.0.0NEWVERSION =3.2.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=Ninject.Web.Common公钥=c7192dc5380945e7文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-3.0.0.0NEWVERSION =3.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Http.WebHost公钥=31bf3856ad364e35文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-5.2.0.0NEWVERSION =5.2.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Net.Http.Primitives公钥=b03f5f7f11d50a3a文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-4.2.22.0NEWVERSION =4.2.22.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=Microsoft.Owin.Security公钥=31bf3856ad364e35文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-2.1.0.0NEWVERSION =2.1.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=Microsoft.AspNet.SignalR.Core公钥=31bf3856ad364e35文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-2.1.2.0NEWVERSION =2.1.2.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=的EntityFramework公钥=b77a5c561934e089文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-6.0.0.0NEWVERSION =6.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=MySql.Data公钥=c5687fc88969c44d文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-6.8.3.0NEWVERSION =6.8.3.0/>
      < / dependentAssembly>
    < / assemblyBinding>
  < /运行>
  < ELMAH>
  < / ELMAH>
< /结构>
 

解决方案

其实从我的服务器删除WebDAV造成应用程序返回一个 503服务不可用错误信息,所以我重新安装了它。

我可以通过禁用WebDAV的针对单个应用程序池来解决这个问题,该停的坏模块的错误。

禁用WebDAV的针对个人的应用程序池:

  1. 单击受影响的应用程序池
  2. 找到 WebDAV创作工具列表
  3. 点击打开它
  4. 点击禁用WebDAV的在右上角。

钽daaaa!

<一个href="http://www.exactsoftware.com/Docs/DocView.aspx?DocumentID=%7Bc288fa96-2eea-414f-843f-29a2a1531405%7D"相对=nofollow>这个环节是哪里来的指示,但它不是很清楚。

I am using WebAPI PUT and DELETE methods to perform actions from my website via AJAX using jQuery. My server is Windows Server 2008 R2 with Plesk installed. POST and GET requests work just fine, but PUT and DELETE fail.

I was originally getting a 401 Unauthorized response when I first deployed my site to the server. I then performed some actions and it turned into 405 Method not allowed.

I am now at a point where I'm receiving an Internal Server error:

Handler "ExtensionlessUrlHandler-Integrated-4.0" has a bad module "ManagedPipelineHandler" in its module list

Now, there are lots of posts about this, and sadly I can't get it to work yet.

Here's what I've tried:

  • Added remove tags within web.config for WebDAV handler and module
  • Set permissions to execute scripts and executables within Handler Mappings
  • Adding the PUT and POST verbs to within IIS
  • Added PUT and POST verbs to the web.config
  • Downloading the .NET Framework and performing a 'repair'
  • Re-registered .NET Framework as shown in this answer
  • Investigated CORS but I'm not doing any cross site scripting, It's just AJAX called from the same domain

How can I get rid of this message and allow my PUT and DELETE to work?

Heres my web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup></configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>
  <connectionStrings></connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="owin:AppStartup" value="uQuiz.OwinStart" />
    <add key="elmah.mvc.disableHandler" value="false" />
    <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
    <add key="elmah.mvc.requiresAuthentication" value="false" />
    <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
    <add key="elmah.mvc.allowedRoles" value="*" />
    <add key="elmah.mvc.allowedUsers" value="*" />
    <add key="elmah.mvc.route" value="elmah" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      <add namespace="Westwind.Utilities" /><add namespace="Westwind.Web" /></namespaces>
    </pages>
    <httpModules>
      <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web" />
      <add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web" />
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /><add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
    <sessionState mode="StateServer" cookieless="false" timeout="60" stateConnectionString="tcpip=loopback:42424" stateNetworkTimeout="3600" />
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers accessPolicy="Read, Execute, Script">
      <!-- Remove WebDAV modules to make PUT methods on WebAPI work -->
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Execute" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
      <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web" />
      <add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web" /><add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /><add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /><add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Ninject.Web.Common" publicKeyToken="c7192dc5380945e7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.22.0" newVersion="4.2.22.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.SignalR.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.8.3.0" newVersion="6.8.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <elmah>
  </elmah>
</configuration>

解决方案

Actually removing WebDAV from my server caused the application to return a 503 Service Unavailable Error message, so I re-installed it.

I was able to fix this by disabling WebDAV for the individual application pool, this stopped the 'bad module' error.

Disable WebDAV for Individual App Pool:

  1. Click the affected application pool
  2. Find WebDAV Authoring Tools in the list
  3. Click to open it
  4. Click Disable WebDAV in the top right.

Ta daaaa!

This link is where I found the instructions but it's not very clear.

这篇关于如何获得PUT和DELETE动词用的WebAPI在IIS工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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