简体   繁体   English

基于角色的Asp.net MVC应用

[英]Role Based Asp.net MVC App

I need to built a simple asp.net mvc app. 我需要构建一个简单的asp.net mvc应用程序。 app requirement is 应用要求是

1) on loading login page will open that ask to login either by general user or administrator 1)在加载登录页面上,将打开要求由一般用户或管理员登录的信息

2) No Sign up or register page . 2)没有注册或注册页面。 Only admin can login and create users. 只有管​​理员可以登录和创建用户。

3) If admin is logged in . 3)如果管理员已登录。 he can create/delete other users and create roles as well. 他可以创建/删除其他用户以及创建角色。

4) Other users can login and perform certain tasks eg data listing and adding/deleting records. 4)其他用户可以登录并执行某些任务,例如数据列表和添加/删除记录。

5) I already have the ms sql server database i want to link to this database for user/role records. 5)我已经有ms sql服务器数据库,我想链接到该数据库以进行用户/角色记录。

Please give me suggestions how can i achieve this? 请给我建议,我该如何实现?

You can start with a default ASP.NET MVC project which provides some sort of membership - ASP.NET Membership/Identity. 您可以从一个默认的ASP.NET MVC项目开始,该项目提供某种类型的成员资格-ASP.NET成员资格/身份。 And then remove certain functionality to disable users from registering a new account. 然后删除某些功能以禁止用户注册新帐户。 Then you can develop your own way of creating an account. 然后,您可以开发自己的帐户创建方式。

You can probably reuse some of the code which you removed earlier to create an account give it permissions etc. 您可能可以重用您先前删除的一些代码来创建一个帐户,为其授予权限等。

** This type of open ended question are normally down voted. **这种类型的开放式问题通常被否决。 You need to be more specific with the problem you are facing and share your analysis . 您需要对所面临的问题更加具体,并分享您的分析 ** **

Anyways here is some tip, You can use SimpleMembershipProvider , it provides all you need for users and role. 无论如何,这里都是一些技巧,您可以使用SimpleMembershipProvider ,它提供了用户和角色所需的全部内容。

If you create a new MVC 4 application in Visual Studio, you will get a precooked working form authentication enabled internet application. 如果在Visual Studio中创建新的MVC 4应用程序,则将获得一个预煮的启用工作表身份验证的Internet应用程序。

Go through the code in AccountController , you will find most of the functionality already implemented with the help of WebSecurity wrapper class. 遍历AccountController的代码,您将发现大多数已经通过WebSecurity包装器类实现的功能。 As Adrian suggested, remove registration part. 正如Adrian建议的那样,删除注册部分。

You can create default role (admin) and users through SQL script or by using Seed method. 您可以通过SQL脚本或使用Seed方法创建默认角色(admin)和用户。

Once you reach that level, you may have some specific question, please share and we will be happy to help. 达到该级别后,您可能会遇到一些具体问题,请分享一下,我们将竭诚为您服务。

You can refer following two links to start with: 您可以参考以下两个链接开始:

http://www.codeguru.com/csharp/.net/net_asp/mvc/using-simplemembership-in-asp.net-mvc-4.htm http://www.codeguru.com/csharp/.net/net_asp/mvc/using-simplemembership-in-asp.net-mvc-4.htm

http://www.codeproject.com/Articles/689801/Understanding-and-Using-Simple-Membership-Provider http://www.codeproject.com/Articles/689801/Understanding-and-Using-Simple-Membership-Provider

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM