登录匿名用户 asp.net 核心网页 API



我正在寻找几天的正确解决方案。我的数据库中存储了用户名和密码。 我只希望特定用户访问某些控制器方法。我如何实现它,通过用户 ID 检查他是否有权限?

谢谢!

您可以在 web api 中实现基本身份验证,在需要提供者用户凭据的特定控制器上添加[Authorize]属性。有关代码示例,请参阅以下文章:

https://codeburst.io/adding-basic-authentication-to-an-asp-net-core-web-api-project-5439c4cf78ee

https://beetechnical.com/rest-api/how-to-validate-rest-api-using-basic-authentication-in-web-api-net-core/

https://jasonwatmore.com/post/2019/10/21/aspnet-core-3-basic-authentication-tutorial-with-example-api

最新更新