ASP.NET - membership provider mvc3 razor - Asked By rahul patil on 20-Jun-12 09:14 AM

an any one tell me how to implement custom membership provider in  MVC3 with razor view i just want to know in this way

        1)create MVC3 application
       2)choose internet template and and Razor view
       3)Add Class  "CustomMembershipProvider " in Models folder ,extend MembershipProvider class ,generate the   code  for not implemented methods  ///here i want to know how to modify the code please provide code
       4)create table for storing users information like Name,Password ,Email in sql server
        5)modify web.confing to support CustomMembershipProvider

  ok i will know only above things what i do for rest of things

also i want that only registerd users can show the welcome page lator on i want roleprovider  so please provide me something so that i complete my work aslo provide detail guidance how to modify code i saw alot of links on google but not getting exact work  please if any one has working code send me thanks 

Jitendra Faye replied to rahul patil on 20-Jun-12 09:42 AM
There are some good links, which will help you to create custom membership provider-

Hope this will help you.
[)ia6l0 iii replied to rahul patil on 20-Jun-12 12:31 PM
You would be surprised to know that there is a solution in CodePlex, that I have used a while back, to get a full-fledged working sample solution that implements Custom Membership Provider. 

You can find the sample @ CodePlex in the following url. Note that this uses Razor model, and Entity framework. 

For your followup question of how to enable custom providers in the configuration file, here are the steps. 
a) Add a configuration file for your application. Web.config, to be precise. 

b) Set up the default provider in the membership node. See below for sample. 
<membership defaultProvider="providername" />

c) Add the Custom member Provider in the membership's provider collection. 
<membership defaultProvider="provider name">
<add name="provider name" type="type of the provider" connectionStringName=""
enablePasswordReset="true"  maxInvalidPasswordAttempts="4" minRequiredNonalphanumericCharacters="0" 
passwordAttemptWindow="10" writeExceptionsToEventLog="false" applicationName="/"

d) Add the Role Manager.
<roleManager defaultProvider="provider name">
<add name="provider name" type="type of the provider" connectionStringName="" applicationName="/" />

Needless to say, your custom membership provider needs to implement the MembershipProvider class as shown in the example below. 

public class myOwnCustomProvider :MembershipProvider
    public override bool ValidateUser(string username, string password) 
    //place all your logic here.

Hope this helped.
Neha Garg replied to rahul patil on 21-Jun-12 05:20 AM


My suggestion is that ASP.NET authentication model is good for this purpose. ASP.NET supports a number of authentication models such as forms, windows, passport, etc.


See the article and step by step description with codes given on the below links: