通过管理控制器为用户提供 Crud
我目前正在开发一个 .net MVC 应用程序,使用内置的用户身份验证系统。我想要的是站点管理员能够登录、列出所有注册用户并能够编辑和创建用户。每个用户都会有一个角色。
我有以下操作:
public ActionResult Index()
{
var users = Membership.GetAllUsers();
return View(users);
}
它允许我显示用户,但它不提供对用户 ID 的访问权限以传递到编辑/创建操作。它也不提供对角色的访问权限(我已经通过配置工具设置了角色)。我是一个 .MVC 菜鸟,所以请为我指出正确的方向。
谢谢,
詹姆斯
I'm currently developing a .net MVC app using the built in authentication system for users. What I want is for a site administrator to be able to log in, list all registered users and have the ability to edit and create users. Each user will have a role.
I have the following action:
public ActionResult Index()
{
var users = Membership.GetAllUsers();
return View(users);
}
which lets me display the users but it does not provide access to a userID to pass through to an edit/create action. Nor does it give access to a role (I have set up a role the configuration tool). I'm a .MVC noob so please point me in the right direction.
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否有必要构建一个应用程序来管理网站管理?有一些应用程序,例如 http://wsat.codeplex.com/ 可以实现您的目标。
如果您需要推出自定义应用程序,我会使其基于角色。即检查当前用户是否具有管理员角色,然后重定向用户以执行 CRUD 操作。类似于 http://msdn.microsoft.com/en-us/ library/ff647401.aspx#paght000013_step4
顺便说一句,如果有很多用户需要管理,您可能需要考虑 GetAllUsers 会减慢您的应用程序的速度。
Is it necessary for you to build an app to manage web site administration? There are apps such as http://wsat.codeplex.com/ which could achieve your objective.
If you need to roll out a custom app, I'd make it role-based. That is check if current user has an admin role and then redirect user to perform the CRUD operations. Something akin to http://msdn.microsoft.com/en-us/library/ff647401.aspx#paght000013_step4
BTW, you may need to consider that GetAllUsers would slow up your app, if there are a lot of users to manage.