webapi <Message>已拒绝为此请求授权。</Message>
webapi <Message>已拒绝为此请求授权。</Message>
原有的调用base.OnAuthorization(actionContext); 换成下面这个
/// <summary>
/// 鉴权
/// </summary>
/// <param name="actionContext"></param>
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;
}
}
/// <summary>
/// 用户授权
/// </summary>
/// <param name="actionContext"></param>
/// <returns></returns>
protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
{
base.IsAuthorized(actionContext);
return true;
}