我正在使用WebAPI PUT和DELETE方法通过AJAX使用jQuery从我的网站执行操作.我的服务器是安装了Plesk的Windows Server 2008 R2. POST和GET请求工作正常,但PUT和DELETE失败.
当我第一次将我的站点部署到服务器时,我最初获得了401 Unauthorized响应.然后我执行了一些操作,它变成了405方法不允许.
我现在正处于收到内部服务器错误的位置:
Handler “ExtensionlessUrlHandler-Integrated-4.0” has a bad module
“ManagedPipelineHandler” in its module list
现在,有很多关于此的帖子,遗憾的是我无法让它工作.
这是我尝试过的:
>在web.config中为WebDAV处理程序和模块添加了删除标记
>设置在Handler Mappings中执行脚本和可执行文件的权限
>将PUT和POST动词添加到IIS中
>在web.config中添加了PUT和POST动词
>下载.NET Framework并执行“修复”
>重新注册.NET Framework为shown in this answer
>调查CORS,但我没有做任何跨站点脚本,它只是从同一个域调用的AJAX
如何摆脱此消息并允许我的PUT和DELETE工作?
继承我的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,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>
我的web.config提取的ExtensionlessUrlHandler-Integrated-4.0.
原文链接:https://www.f2er.com/ajax/160165.html看看你和我之间的区别我没有这个部分resourceType =“Unspecified”requireAccess =“Execute”.我也使用verb =“*”这不应该有所作为,但可能值得一试.
另请注意,我在处理程序部分中没有accessPolicy =“Read,Script”属性.我也不删除WebDAV.
<system.webServer> <handlers> <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>
可能的答案来自:https://stackoverflow.com/a/18458139/1398425
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET,DELETE" /> <add name="Access-Control-Allow-Headers" value="Content-Type" /> </customHeaders> </httpProtocol> <modules runAllManagedModulesForAllRequests="false"> <remove name="WebDAVModule" /> </modules> <validation validateIntegratedModeConfiguration="false" /> <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,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,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer>