英文:
Role Based Authorization in ASP.NET Core 6
问题
我正在开发一个ASP.NET Core 6 Web应用程序。
- 该应用程序将通过IIS在独立的机器上运行。
- 将没有注册或登录功能。
- 该应用程序将支持并具有两个用户“KioskAdmin”和“KioskUser”的功能。这两个用户是运行应用程序的主机机器的机器帐户。因此,用户以“KioskAdmin”的身份登录到机器上,该用户将可以访问应用程序的管理功能。如果一个人以“KioskUser”的身份登录到主机机器上,该人将可以访问非管理员功能。
我想使用基于角色的授权,我可以这样做
[Authorize(Roles = "Admin")]
public class IndexModel : PageModel
我已经阅读了关于基于声明的授权和cookie身份验证以及创建身份用户的文章,但不确定如何实现它。而且,KioskAdmin和KioskUser的机器帐户用户名将在应用程序最终部署的每台机器上都不同。
是否有一种方法可以将[Authorize(Roles = "Admin")]
与我实现自己的代码/逻辑并返回某个值以表示授权有效的自定义方法联系起来?
英文:
I'm developing an ASP.NET Core 6 web application.
- The application will run via IIS on a standalone machine
- There will be no Register or login functionality.
- The application will support and have functionality for two Users "KioskAdmin" and "KioskUser". Those two Users are machine accounts of the host machine running the application. So a User logs into the machine as "KioskAdmin" and the person has access to the administrative functionality of the application. If a person logs into the host machine as "KioskUser" the person has access to non-admin functionality.
I'd like to use Role based authorization where I can do
[Authorize(Roles ="Admin")]
public class IndexModel : PageModel
I've read about Claims-based authorization and cookie authentication and creating an Identity User, but not sure how to implement it. Plus the machine account username for both KioskAdmin and KioskUser is going to be different for every machine the application is eventually deployed on.
Is there a way to tie [Authorize(Roles ="Admin")]
to some custom method where I implement my own code/logic and return some value that would signal the Authorization was valid?
答案1
得分: 0
我找到了对我有效的东西。实现自定义授权属性。
在ASP.NET Core中的自定义AuthorizeAttribute
英文:
I found something that works for me. Implement custom Authorize attribute.
custom AuthorizeAttribute in ASP.NET Core
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论