码迷,mamicode.com
首页 > Windows程序 > 详细

webapi <Message>已拒绝为此请求授权。</Message>

时间:2017-02-03 21:51:38      阅读:6808      评论:0      收藏:0      [点我收藏+]

标签:top   没有   serial   count   tps   content   拒绝   oid   eid   

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;
}

webapi <Message>已拒绝为此请求授权。</Message>

标签:top   没有   serial   count   tps   content   拒绝   oid   eid   

原文地址:http://www.cnblogs.com/zhian/p/6363424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!