添加授权标头并在控制器中进行验证

时间:2013-06-20 04:11:01

标签: asp.net-mvc-4 asp.net-web-api authorization

在我的ASP.Net Web API项目中,我向控制器添加了[Authorize]属性。因此,当我调用该方法时,它将返回错误

"Message": "Authorization has been denied for this request."

如何发送Authorize标题以及我的请求。

控制器

[Authorize]
[HttpPost]
public HttpResponseMessage Settings(SettingModel data)
{
    --Do i need to check authorize headers manually here?
    --code goes here
}

这里称为

http://localhost/sample/api/Settings

Headers
{
   Content-Type: application/json
   Authorization: What value need to be send here?
}

1 个答案:

答案 0 :(得分:0)

检查达林的答案:How to do role based authorization for asp.net mvc 4 web api

我想你需要注册处理程序..