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