尝试使用微软的Web Api,他的确是一个很有意思的东西。
让我体会到了许多的方便,但是我发现部署到IIS服务器上去了后PUT和Delete请求将返回405.
原因是IIS的默认处理程序默认情况下只允许GET,POST,HEAD和调试方法。而不能使用PUT和Delete操作。
此时也很简单只需要在Web配置文件中做如下修改即可:
- <system.webServer>
- <modules runAllManagedModulesForAllRequests="true">
- <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>