Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom MembershipProvider in MVC 4

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.

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.

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

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

like image 606
Darf Zon Avatar asked Dec 28 '12 02:12

Darf Zon


1 Answers

NOTE: Below may not be applicable for .NET Core or ASP.NET Core

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)

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

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)

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)

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.

UPDATE

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

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.

like image 76
Madushan Avatar answered Oct 05 '22 23:10

Madushan