webapi 已拒绝为此请求授权。

webapi 已拒绝为此请求授权。

原有的调用base.OnAuthorization(actionContext); 换成下面这个

 

///


/// 鉴权
///

///
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
//判断是否登录或是否用权限,如果有那么就进行相应的操作,否则跳转到登录页或者授权页面
Ruankaowang_Model.Model.Account m_account = LoginComm.GetAccount(); //_51sole_soulefu_Framework.Login.LoginComm.GetAccountByCookieid();
//判断是否有cookie
if (m_account != null)
{
//base.OnAuthorization(actionContext);
IsAuthorized(actionContext);
return;
}
else
{
ResponseModel model = new ResponseModel();
model.Code = (int)ResponseEnum.Userisnotloggednotoperate;
model.Msg = "用户没有登录不能进行操作";
string json = JsonConvert.SerializeObject(model);

StringContent Content = new StringContent(json, Encoding.GetEncoding("UTF-8"), "application/json");
HttpResponseMessage message = new HttpResponseMessage();
message.StatusCode = HttpStatusCode.OK;
message.Content = Content;
actionContext.Response = message;
}
}
///


/// 用户授权
///

///
///
protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
{
base.IsAuthorized(actionContext);
return true;
}

转载于:https://www.cnblogs.com/zhian/p/6363424.html

你可能感兴趣的:(webapi 已拒绝为此请求授权。)