zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    1113 Integer Set Partition
    1114 Family Property
    1115 Counting Nodes in a BST
    1116 Come on! Let's C
    Maven 常用命令
    Maven 快照
    Maven 插件
    Maven POM
    Maven 中央仓库
    Maven 依赖机制
  • 原文地址:https://www.cnblogs.com/zhian/p/6363424.html
Copyright © 2011-2022 走看看