這個錯誤是很常見的,我嘗試了所有的解決方案,而不是他們的工作。我在控制面板中禁用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