我创建了一个自定义授权类来验证用户令牌。这是网络 API 2。问题是,自定义授权验证了令牌,但之后不执行控制器中的方法。验证令牌后,它应该在控制器中执行用户方法。我已经调试了代码,我可以看到授权令牌得到了正确验证,但没有执行该方法,只是返回 200。任何人都可以帮忙吗?(我是新来的)自定义授权类代码:public class CustomAuthorize : System.Web.Http.AuthorizeAttribute { public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { base.OnAuthorization(actionContext); if (actionContext.Request.Headers.Authorization.Parameter != null) { string authenticationToken = Convert.ToString(actionContext.Request.Headers.Authorization.Parameter); PartnerUserProfile user = new PartnerUserProfile(); user = user.validate_token(authenticationToken); if (user.recordref > 0) //above user has some content and matches the token from validate_token method. it wil be blank if not { return; } else { HttpContext.Current.Response.AddHeader("Bearer", authenticationToken); HttpContext.Current.Response.AddHeader("AuthenticationStatus", "NotAuthorized"); actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden); return; } } actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed); actionContext.Response.ReasonPhrase = "Please provide valid inputs"; return; } }而我的控制器低于这个永远不会被执行。 [HttpPost] [CustomAuthorize] public IHttpActionResult user(PartnerUserProfile user) //setUser { ReturnData rd = user.setPartnerUserProfile(); if (rd.status == 0) { return BadRequest("Invalid"); } return Ok(rd); }
1 回答
- 1 回答
- 0 关注
- 207 浏览
添加回答
举报
0/150
提交
取消