Azure Active Directory 入门(WebApi 项目)Get Started with Azure Active Directory (WebApi projects)

本文提供通过 Visual Studio 的“项目”>“连接的服务” 命令将 Active Directory 添加到 ASP.NET WebAPI 项目后的其他指南。This article provides additional guidance after you've added Active Directory to an ASP.NET WebAPI project through the Project > Connected Services command of Visual Studio. 如果尚未将该服务添加到你的项目,可以随时执行该操作。If you've not already added the service to your project, you can do so at any time.

请参阅我的 WebAPI 项目发生了什么情况?,了解添加连接服务时对项目所做的更改。See What happened to my WebAPI project? for the changes made to your project when adding the connected service.

访问控制器需要身份验证Requiring authentication to access controllers

项目中的所有控制器均带有 [Authorize] 属性。All controllers in your project were adorned with the [Authorize] attribute. 此属性要求用户先进行身份验证,才能访问由这些控制器定义的 API。This attribute requires the user to be authenticated before accessing the APIs defined by these controllers. 若要允许匿名访问控制器,请从控制器删除此属性。To allow the controller to be accessed anonymously, remove this attribute from the controller. 如果想要更详细地设置这些权限,请将该属性应用到需要身份验证的每个方法,而不是将它应用到控制器类。If you want to set the permissions at a more granular level, apply the attribute to each method that requires authorization instead of applying it to the controller class.

后续步骤Next steps