Refitを使用してIHttpActionResult
を返すAPI呼び出しがあります。コントローラではない一般的なUnAuthorized IHttpActionResultを作成する方法
[Patch("/api/userprofile/")]
[Headers("Authorization: Bearer")]
Task<IHttpActionResult> UpdateUserProfile(UserProfile user);
APIコールを処理する別のDLLで別のクラスを作成しました。
public async Task<IHttpActionResult> UpdateUserProfile(UserProfile profile)
{
if (HttpContext.Current.Request.IsAuthenticated)
{
var ups = ApiServiceFactory.GetUserProfileService();
var result = ups.UpdateUserProfile(profile);
return result.Result;
}
return ???;
}
このクラスは、現在APIControllerから派生していないので、どのように私はIHttpActionResult
から継承するオブジェクトを作成することができます。 ResponseMessage、HttpResponseMessage、Ok、Conent(Status、Message)を試しました。これらのほとんどはAPIContollerから派生する必要があります。それはただ1つのオブジェクトを作成するだけの過度な作業のようです。
したがって、IHttpActionResultを継承するオブジェクトを作成して、プレーンなクラス/メソッドから401のようなものを返すことはできますか?
これを書き留めていただきありがとうございます。 IHttpActionResultは、呼び出しが失敗した理由のステータステキストを返して、キャプチャして渡したいと思っています。 – Mike
@みんな私の答えを更新しました。 – krillgar