在 asp.net mvc 默认应用程序中,您将获得帐户 Controller ,该 Controller 允许用户注册、登录、注销和更改密码。
我想知道是否可以实现更多的功能,例如允许管理员删除某些用户或为某些用户提供不同的角色,例如在 asp.net 配置中创建用户、角色并将角色分配给用户?
我已经弄清楚并扩展了用户的个人资料,所以现在他们有了更多的信息和个人资料图片。
如果您有asp.net mvc中用户管理的经验或例子。
最佳答案
虽然有点过时,但这个项目也许可以给您一些关于如何在 ASP.NET MVC 中实现成员资格管理的提示:
Asp.Net MVC Membership Starter Kit
报价
What is the Asp.Net MVC Membership Starter Kit?
The starter kit currently consists of two things:
- A sample website containing the controllers, models, and views needed to administer users & roles.
- A library that provides testable interfaces for administering users & roles and concrete implementations of those interfaces that wrap the built-in Asp.Net Membership & Roles providers.
Out of the box, the starter kit gives you the following features:
- List of Users
- List of Roles
- User Account Info
- Change Email Address
- Change a User's Roles
更新
为了将某些操作限制为特定的用户角色,您可以使用我之前提到的项目创建这些角色,然后使用 Authorize 属性装饰您自己的应用程序的 Controller 和/或操作,引用所需的角色:
[Authorize(Roles = "Administrator, HR")]
public ActionResult DeleteUser(int UserId)
{
// do something
}
这将防止非管理员或 HR 的用户删除用户。
关于Asp.net mvc用户管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6548060/