在MVC 4定制的MembershipProvider [英] Custom MembershipProvider in MVC 4

查看:130
本文介绍了在MVC 4定制的MembershipProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个开始了解MVC4。作为第一步,我需要因为与数据库中只有三个角色自定义数据库进行登录。

I'm a starting to learn about MVC4. As first steps, I need to perform a login since a custom database with just three roles in the database.

难道真的要实现自定义成员资格提供?我的问题是因为我正在读这篇文章,他在做另一种方式:<一href=\"http://patrickdesjardins.com/blog/asp-net-membership-with-mvc4\">http://patrickdesjardins.com/blog/asp-net-membership-with-mvc4

Is it realy necessary to implement a custom membership provider? I'm question this because I was reading this post and he's doing another way: http://patrickdesjardins.com/blog/asp-net-membership-with-mvc4

我只需要从自定义数据库获得用户和确定角色。

I just need to get users from a custom database and determine the role.

要确定的规则,是一个相当简单的。我有两个表名为学生和教师。每个人都有其ID作为是洛ID和共同财产的密码。

To determine the rule, is a quite simple. I've got two tables called Students and Teachers. Each one has its Id as is loggin Id, and the common property password.

if (db.Students.Where(x => x.StudentId == x && x.Password == y) return "student"
if (db.Teachers.Where(x => x.TeacherId == x && x.Password == y) return "teacher"

// does not exist

您可以定位我关于如何实现此功能在ASP.NET?

Can you orient me about how to implement this features in ASP.NET?

推荐答案

在开始之前你的研究,注意成员和角色管理已在ASP.NET MVC4被改变。 (如果你使用的Visual Studio的互联网应用程序模板)

Before you start your research, note that membership and role management has been changed in ASP.NET MVC4. (if you're using 'Internet Application' template from Visual Studio)

请阅读乔恩·加洛韦的<一个href=\"http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx\"相对=nofollow>博客文章什么改变了。

Please read Jon Galloway's blog post about what has changed.

新建简单成员资格提供的设计进行扩展和克服​​老成员和角色管理系统的问题(仍支持的,因为它是ASP.NET的一部分)

New Simple Membership Provider is designed to be extended and overcome issues in the old membership and role management system (which is still supported as it is a part of ASP.NET)

两者的实现都支持角色的管理,你可以自由地选择执行,或推出自己。还有,因为两者的限制参数上比较好,而一些开发商preFER实施自己。 (我不会详谈,因为它可以得到偏)

Both implementations support role management, and you're free to select either implementation, or roll your own. There are arguments on which is better, and some developers prefer implementing their own, because of the limitations of both. (I won't go into details, as it can get biased)

下面是让你开始的教程。 [链接] .. 请注意,教程解释老会员制,而不是新的SimpleMembership / WebSecurity方法。

Here's a tutorial to get you started. [Link].. Please note that tutorial explains the old membership system, and not the new SimpleMembership/WebSecurity method.

更新

当你认为你有足够的验证框架,微软已经宣布 OWIN - 打开网页接口.NET

Just when you think you have enough authentication frameworks, Microsoft has announced OWIN - Open Web Interface for .NET.

OWIN是一组用于.NET这是开放的,可插拔的接口,这包括认证。请参考这个帖子[<一个href=\"http://blogs.msdn.com/b/webdev/archive/2013/07/03/understanding-owin-forms-authentication-in-mvc-5.aspx\"相对=nofollow>链接]关于如何使用MVC 5 OWIN窗体身份验证。 (希望他们会停止创建这一新的认证框架。)

OWIN is a set of interfaces for .NET which are open and pluggable, and this includes authentication. Please refer to this post [Link] on how to use MVC 5 OWIN Forms Authentication. (Hopefully they'll stop creating new authentication frameworks with this.)

这篇关于在MVC 4定制的MembershipProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆