I have API controller
with method:
[Route("campaigns")]
[HttpDelete]
public async Task<IHttpActionResult> Delete(string brandId,string campaignId)
{
try
{
var merchantId = CurrentUserInfo.GetMerchantId();
await _service.DeleteAsync(merchantId, brandId, campaignId);
return StatusCode(HttpStatusCode.NoContent);
}
catch (Exception e)
{
Log(e);
return BadRequest(e.Message);
}
}
And from angularJS
app
I sending request:
$http.delete(config.resourceNames.campaign, { params: { brandId: brandId, campaignId: campaignId } })
.then(function (response) {
return response;
}, function (error) {
return error;
});
Config file:
var resourceNames = {
campaign: '/api/campaigns'
};
So the routing is valid. But the request always return 404 NOT FOUND
.
I checked it via Swagger
and that DELETE
method is visible at the list but when I try to use it. It also return NOT FOUND
.
Why this happing?
Edit:
While using "ISS Express" there is error 404 but when I switch to "Local ISS" the error change to 405 Method not allowed.
可能你需要写:
[Route("api/campaigns")]
I have run into this a couple of times. While I am not certain what the underlying cause is, I can say that naming routes has helped tremendously. Try this:
[Route("campaigns", Name = "delete-campaign")]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.