此请求的授权已被拒绝-新的Web API项目 [英] Authorization has been denied for this request - New Web API Project

查看:556
本文介绍了此请求的授权已被拒绝-新的Web API项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Visual Studio 2015中创建了一个新的Web API项目(使用MVC),出于测试目的,我运行了该项目,但最终出现错误.

I just created new Web API project (using MVC) in visual studio 2015 and for the testing purpose, I ran that project but ended up below error.

运行项目后,它会正确显示主页",但是当我导航到/api/values或/api/values/5时,它会在xml消息下方显示

After running the project, it brings up Home Page correctly but when I navigated to /api/values or /api/values/5, it gives me below xml message.

<Error>
    <Message>Authorization has been denied for this request.</Message>
</Error>

有人可以帮忙吗?我是Web API的新手. 请注意,我不想删除Authorize属性.我只想在授权后访问资源.所以我在找什么地方错了.

Can someone please help? I am new to Web API. Please note that I don't want to remove the Authorize attribute. I would like to access the resource after authorization only. So I am looking for what is wrong.

推荐答案

在ValuesController中,如果删除了属性Authorize,它将作为主页使用.

In the ValuesController there is an attribute Authorize if you remove it, then it will work as home page.

Authorize属性仅阻止匿名用户访问ValuesController.

The Authorize attribute just prevent an anonymous users from accessing the ValuesController.

要使用此属性,您需要首先注册一个用户,然后登录以获取用户的令牌,然后您可以使用该令牌来授权自己并获得访问权限.

to work with this attribute, you need first to register a user, and then login to get user's token, then you can use the token to authorize your self and get access .

在此页面中 Individual-accounts-in-web-api 解释了您的全部需求

In this page Individual-accounts-in-web-api is explained all what do you need

这篇关于此请求的授权已被拒绝-新的Web API项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆