我最近从Visual Studio 2010升级到Visual Studio 2012 RC.安装程序还会安装IIS 8 Express,Visual Studio现在将其用作默认Web服务器.
IIS 8阻止了我使用PUT AND DELETE谓词的WEB API请求.IIS返回405错误,The requested resource does not support http method 'PUT'.
我知道过去人们对此有疑问,Stack Overflow上有几条关于它的消息.使用IIS 7 Express,解决方案是卸载WebDav.不幸的是,我没有看到任何与IIS 8相关的方法.
我已经尝试从applicationhost.config编辑出WebDav部分,但这没有帮助.例如,我<add name="WebDAVModule" image="%IIS_BIN%\webdav.dll" />从配置文件中删除了.
我花了很长时间才研究这个问题.必须有一种简单的方法来启用PUT和DELETE?
这是PUT我的Web API上方法的调用- 方法的第三行(我从ASP.NET MVC前端调用Web API):

client.BaseAddress是http://localhost/CallCOPAPI/.
这是contactUri:

这是contactUri.PathAndQuery:

最后,这是我的405回复:

这是我的Web API项目中的WebApi.config:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiGet",
routeTemplate: "api/{controller}/{action}/{regionId}",
defaults: new { action = "Get" },
constraints: new { httpMethod = new HttpMethodConstraint("GET") });
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
Run Code Online (Sandbox Code Playgroud)
我试着剥离下来获取传递到路径PutAsJsonAsync,以string.Format("/api/department/{0}", department.Id)和string.Format("http://localhost/CallCOPAPI/api/department/{0}", department.Id)没有运气.
有没有人有任何想法为什么我得到405错误?
UPDATE
根据请求,这是我的部门控制器代码(我将发布我的前端项目的部门控制器代码,以及WebAPI的部门ApiController代码):
前端部门控制员 …
我最近不得不设置Access-Control-Allow-Origin为*能够进行跨子域ajax调用.
现在我不禁觉得我的环境存在安全风险.
如果我做错了,请帮助我.
这个错误非常普遍,我尝试了所有的解决方案,但没有解决.我在控制面板中禁用了WebDAV发布,并将其添加到我的Web配置文件中:
<handlers>
<remove name="WebDAV"/>
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
Run Code Online (Sandbox Code Playgroud)
错误仍然存在.这是控制器:
static readonly IProductRepository repository = new ProductRepository();
public Product Put(Product p)
{
return repository.Add(p);
}
Run Code Online (Sandbox Code Playgroud)
方法实施:
public Product Add(Product item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
item.Id = _nextId++;
products.Add(item);
return item;
}
Run Code Online (Sandbox Code Playgroud)
这就是引发异常的地方:
client.BaseAddress = new Uri("http://localhost:5106/");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsJsonAsync("api/products", product);//405 exception
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我刚刚开始学习Flask,我正在尝试创建一个允许POST方法的表单.这是我的方法:
@app.route('/template', methods=['GET', 'POST'])
def template():
if request.method == 'POST':
return("Hello")
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
我的index.html:
<html>
<head>
<title> Title </title>
</head>
<body>
Enter Python to execute:
<form action="/" method="post">
<input type="text" name="expression" />
<input type="submit" value="Execute" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
加载表单(在收到GET时呈现它)工作正常.但是,当我单击提交按钮时,我收到POST 405错误方法不允许.为什么不显示你好?
在我的Web API项目中,我无法执行HTTP PUT我的资源.我已经阅读了一些 关于这个问题的类似 问题 , 并且我遵循了建议的建议.
首先,我在我的机器上完全卸载了WebDAV(Windows 7 64位),然后重新启动了我的机器.
其次,WebDAV处理程序在我的指定中被删除,web.config并且HTTP PUT动词被指定为允许无扩展URL处理程序.
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="WebDAV"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0"
path="*."
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
resourceType="Unspecified"
requireAccess="Script"
preCondition="integratedMode,runtimeVersionv4.0" />
<add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
</handlers>
Run Code Online (Sandbox Code Playgroud)
我甚至尝试添加ISAPI无扩展URL处理程序(32位和64位)并将我的应用程序从集成管道应用程序池更改为经典应用程序池.
<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" />
Run Code Online (Sandbox Code Playgroud)
我目前正在使用Thinktecture IdentityModel来启用跨源资源共享(CORS)支持.为了我的理智,我已经选择了启用一切以确保HTTP …
我有一个Web API项目,我无法启用"PUT/Patch"请求.
我从小提琴手得到的回应是:
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET,POST,DELETE
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcZG90TmV0XFdlYkFQSVxBZFNlcnZpY2VcQWRTZXJ2aWNlXGFwaVxpbXByZXNzaW9uXDE1?=
X-Powered-By: ASP.NET
Date: Tue, 06 May 2014 14:10:35 GMT
Content-Length: 72
{"message":"The requested resource does not support http method 'PUT'."}
Run Code Online (Sandbox Code Playgroud)
根据上述回复,不接受"PUT"动词.但是,我无法弄清楚相关处理程序的配置位置.
类的"Put"方法声明如下:
[HttpPatch]
[HttpPut]
public HttpResponseMessage Put(Int32 aID, [FromBody] ImpressionModel impressionModel)
{
bla, bla, bla, bla
}
Run Code Online (Sandbox Code Playgroud)
我已阅读并实现了以下主题中解释的更改: - Asp.NET Web API - 405 - 不允许用于访问此页面的HTTP动词 - 如何设置处理程序映射 - http://www.asp.net/web -API /概述/测试和调试/故障排除-HTTP-405-错误-后发布的Web-API的应用程序
没有任何工作,因为我在尝试对我的Web API项目发出"PUT"命令时仍然得到405响应.
我甚至在ApplicationsHost.config文件中注释掉了所有"处理程序". …
我有一个新的iis服务器,从一段时间以来我找到了错误的解决方案:
405 - 不允许用于访问此页面的HTTP动词.无法显示您要查找的页面,因为使用了无效的方法(HTTP谓词)来尝试访问.
我见过以下解决方案:
1.
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
2. IIS设置http://www.somacon.com/p126.php
解决方案1,导致内部服务器错误,以后无法找到解决方案.解决方案2,我无法在iis 8.5中找到Property窗口,因此无法尝试相同的操作.
请帮忙
我检查了一切,没有一个配置工作正常.
THE GET,POST正在工作但是我得到了405消息.我没有WebDEV.
这是我的配置.
<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>
Run Code Online (Sandbox Code Playgroud)
它让我疯了!
我已经提到了所有可用的建议,例如: Asp.NET Web API - 405 - 不允许用于访问此页面的HTTP动词 - 如何设置处理程序映射

即使我使用Basic Auth/Windows Auth.禁用它也没有区别.
[System.Web.HttpHttpPut] public override HttpResponseMessage Put(int id,Request entity){....}
注意:我刚刚安装了登台服务器,它已经运行了.但是,它不能在我的机器上工作......
