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

Earn up to 20 extra points for answering this tough question.
an any one tell me how to implement custom membership provider in asp.net  MVC3 with razor view i just want to know in this way

        1)create ASP.net 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-

http://www.codeproject.com/Articles/165159/Custom-Membership-Providers
http://www.codeproject.com/Articles/13032/Custom-MembershipProvider-and-RoleProvider-Impleme


http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

http://www.shiningstar.net/ASPNet_Articles/CustomProvider/CustomProvider.aspx

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.
http://custommemberprovider.codeplex.com/releases/view/84184 

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">
<providers>
<add name="provider name" type="type of the provider" connectionStringName="con.string.name"
enablePasswordReset="true"  maxInvalidPasswordAttempts="4" minRequiredNonalphanumericCharacters="0" 
passwordAttemptWindow="10" writeExceptionsToEventLog="false" applicationName="/"
/>
</providers>
</membership>

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

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

Hi


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:


http://www.brianlegg.com/post/2011/05/09/Implementing-your-own-RoleProvider-and-MembershipProvider-in-MVC-3.aspx


http://www.danharman.net/2011/06/23/asp-net-mvc-3-custom-membership-provider-with-repository-injection/