0
我有一個簡單的資源,它提供了一個翻譯列表。獲取終點需要一種語言並返回翻譯字典。任何更新都只會在一個翻譯上進行,所以我認爲這適合做一個補丁。.NET web api HttpPatch返回403禁止
在我的api控制器中,我可以做一個放置工作,但是我給我的補丁端點做的任何調用都會給我一個403禁止的錯誤,我不明白爲什麼。
[HttpGet]
// GET api/<controller>
public Dictionary<string,string> Get(String id)
{
return TranslationSvc.GetTranslatedStrings(id);
}
[HttpPatch]
public TranslationEntry Patch(TranslationEntry data)
{//403 prevents this end point from ever executing
if (TranslationSvc.UpdateTranslation(data.Lang, "", data.Translation.Key, data.Translation.Value))
{
return data;
}
else
{
//return a 500 error;
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}
[HttpPut]
public TranslationEntry Put(TranslationEntry data)
{//works, but technically a put should be the full resource which is the full collection
if (TranslationSvc.UpdateTranslation(data.Lang, "", data.Translation.Key, data.Translation.Value))
{
return data;
}
else
{
//return a 500 error;
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}