这个错误是很常见的,我尝试了所有的解决方案,而不是他们的工作。我在控制面板中禁用WebDAV发布,并将此向我的网络配置文件:405方法不允许web api
<handlers>
<remove name="WebDAV"/>
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
错误仍然存在。这是控制器:
static readonly IProductRepository repository = new ProductRepository();
public Product Put(Product p)
{
return repository.Add(p);
}
方法实现:
public Product Add(Product item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
item.Id = _nextId++;
products.Add(item);
return item;
}
而这正是引发异常:
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
有什么建议?
不断让我这一个! – Rick
这解决了我的问题。谢谢... – Ziggler
这解决了我的MVC API属性不起作用。谢谢! – Alexei