Code snippet to implement custom membership provider in ASP.NET MVC

Posted on 2010-09-16
Last Modified: 2013-11-08
I want to implement a custom membership provider in an MVC app.   I am already using forms authentication and  I have a simple database schema for membership/roles that comprises of two tables as only one user can be in one role.

Here are My table schema is in the code snippet below.

I currently check for a user's role by doing

if (User.userRole.roleName == "admin")////

But want to implement custom membership/roles so I need a code snippet that would implement the provider.   T


UserID           Int

RoleID           Int

Username         varchar(100)

AreaID           int

FirstName        varchar(100)

Surname          varchar(100)

Password         varchar(100)

Email            varchar(100)

CreatedOn        datetime

ModifiedOn       datetime

IsAuthorised     bit


RoleID           int

RoleName         varchar(100)


AreaID           int

AreaName         varchar(100)

Open in new window

Question by:ToString1
  • 3
  • 2

Expert Comment

ID: 33690600

Author Comment

ID: 33690644
OK thanks

I am using linq to sql so would want something in that.  I do not want to write stored procedures

Accepted Solution

roxviper earned 500 total points
ID: 33690677

Author Comment

ID: 33690711
OK that is interesting

In my MVC app I am implementing forms authentication and nothing else

So with this post

Can I implement role based authentication, ie,  I want to partition off admin and superadmin parts of the app

Assisted Solution

roxviper earned 500 total points
ID: 33690764
In fact if you import the right libraries, you can use the same functionality as you used for Web Forms. Personally, I make the same functionality.

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now