İnsanları yetkilendirmek için web api'm için bir ActionFilterAttribute oluşturdum. RequestUri'nin RequestUri'ye erişmesi tamam, ancak bunu form verilerinde göndermek istiyorum. ActionFilterAttribute onActionExecuting yönteminde Request.Content okurken, sunucunun her zaman boş bir sonucu olur. Bu sorunu nasıl çözebilirim? kod aşağıda gibi gibidir: HttpContent ActionFilter önce biçimlendiricisine tarafından okundu çünküForm Verilerini Okuma ActionFilterAttribute
public class RequireAuthorization : ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
actionContext.Request.Content.ReadAsStringAsync().ContinueWith((t) =>
{
try
{
//query will result in empty string
string query = t.Result;
string UserID = HttpUtility.ParseQueryString(query).Get("UserID");
string accessToken = HttpUtility.ParseQueryString(query).Get("AccessToken");
UserRepository repository = new UserRepository();
repository.IsTokenValid(Convert.ToInt32(UserID), accessToken);
}
catch (Exception ex)
{
var response = new HttpResponseMessage
{
Content =
new StringContent("This token is not valid, please refresh token or obtain valid token!"),
StatusCode = HttpStatusCode.Unauthorized
};
throw new HttpResponseException(response);
}
});
base.OnActionExecuting(actionContext);
}
}
cevabını buldunuz mu? Aynı problem yaşıyorum – Ahmadreza