Asp.net mvc用户管理

标签 asp.net asp.net-mvc asp.net-mvc-3 asp.net-membership

在 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:

  1. A sample website containing the controllers, models, and views needed to administer users & roles.
  2. 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/

相关文章:

asp.net - 保留文件上传控件中的值

c# - 如何将来自 WebClient 的字节数组响应转换为 Xml?

c# - 动态 Action 链接

asp.net - 将免费提供的 Asp.Net 论坛与 MySQL 数据库上的 Asp.net Web 应用程序集成

javascript - Ajax.beginForms MVC 部分 View

asp.net - 使用 Razor View Engine 将内容从部分 View ASP.NET MVC 3 注入(inject)特定部分

asp.net-mvc - 为什么@Model 为空?

jquery - 带有值和文本字段的 ASP.NET MVC jquery 自动完成

Asp.NET MVC 路由性能

c# 使用数据库 MVC 中的数据创建 Rss-Feed