Here i'm explaining how to Create And Use Custom MemberShip Provider Database in ASP.NET 2.0,3.5.4.0.
If you want to use Custom or your own DataBase as membership Provider instead of ASPNETDB.MDF database provided by asp.net membership provider class, than follow the steps mentioned in this article.
In this example i m going to describe how to change and use custom Database with Login Control in ASP.NET.
First of all you need to create DataBase schema for membership.
For this create a DataBase in sql server with any name you want.
Now open Visual studio command prompt and type aspnet_regsql , press enter
this will open wizard window to setup database for membership provider
Alternatively you can Go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and run aspnet_regsql.exe from there
Follow the steps according to images
Now open web.config file and write below mentioned code
After this click on website menu in Visual Studio and select ASP.NET Configuration
GO to Provider Tab and click on Select a different provider for each feature (advanced) option
Now create users by going to security tab
Your custom membership provider with your own custom databse configuration is done
Build and test the application
In this example i m going to describe how to change and use custom Database with Login Control in ASP.NET.
First of all you need to create DataBase schema for membership.
For this create a DataBase in sql server with any name you want.
Now open Visual studio command prompt and type aspnet_regsql , press enter
this will open wizard window to setup database for membership provider
Alternatively you can Go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and run aspnet_regsql.exe from there
Follow the steps according to images
Choose your Database Server and DataBase Name
Now open web.config file and write below mentioned code
Add connection string
Now add this code in System.web section of web.config<connectionStrings> <add name="ConnectionString" connectionString="server=AVDHESH\SQLEXPRESS; database=CustomMembership;uid=amit;password=password;"/> </connectionStrings>
<roleManager defaultProvider="CustomProvider"> <providers> <add connectionStringName="ConnectionString" name="CustomProvider" type="System.Web.Security.SqlRoleProvider" /> </providers> </roleManager> <membership defaultProvider="CustomMembershipProvider"> <providers> <add name="CustomMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnectionString" /> </providers> </membership>
After this click on website menu in Visual Studio and select ASP.NET Configuration
GO to Provider Tab and click on Select a different provider for each feature (advanced) option
Now create users by going to security tab
Your custom membership provider with your own custom databse configuration is done
Build and test the application
If you like this post than join us or share
40 comments:
You can't believe how much you just helped me. Thanks you so much.
hey amit,
thanks.
u saved many hours of mine.
this is very good.I used it in my application.when i run my website using visual Studio connected with remote db it works nice but when i deploy it on net than it shows password is incorrect.i tryed it more than two user but the problem is same.please help i need help very urgent.plzzzzzzzzzzzzzz.kshatriya2255@gmail.com
@abhishek Singh:
Please check the connection string in Your web.config file under membership defaultProvider="CustomMembershipProvider" section
Hi Amit,
Thanks for breaking this down so nicely. I book-marked you on Stumble and Digg. Good work!
Sean
@Sean Olson:
Thanks a lot for the appreciation and favor :)
Keep visiting
thanks amit!
i will sleep today properly after
one week .
thnks again
uzz
good looking
awesome BRO helped alot, i took 2 hrs in configuring this ~am new to asp.net thanks not
AmiT i am trying to set up authentication from a databse called student.mdf with a table names Auth with name and psw feilds i dont think whats above can help me, any thing u can help me with?
Ravinsal
Many institutions limit access to their online information. Making this information available will be an asset to all.
I already did this. How can I authenticate the 2nd page? Example, if I will type the url of the second page, I will not access it unless I enter my username and password whether I'm an admin or not.
Hello Amit,
I have a question. When I start aspnet_regsql.exe, the procedure creates tables structure into a db. But can I use different tables structure ? I need to use other tables structure that defines roles and permissions at different level, instead of its own structure.
Thank you
Dombar
It was certainly interesting for me to read that post. Thank you for it. I like such topics and anything that is connected to this matter. I definitely want to read a bit more soon.
Thanks, it works great!!!
please update at time
It was very interesting for me to read that post. Thanks for it. I like such themes and anything that is connected to them. BTW, try to add some photos :).
To create DataBase schema for membership:-
Command Line did the trick:-
C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql -S 206.51.227.199 -A
m -U -P l
Start adding the following features:
Membership
......................
Finished.
C:\Windows\Microsoft.NET\Framework\v2.0.50727>
Don't know why Wizard was behaving idiotic and throwing error.
Thanks,
Thank you so much
hey man.. u describe to chose custom membership in database but i got the option of choosing
master,msdb,tempdb,model.... indeed there's no custom membership option.. in database
what to do.. now?
plz help.. waiting for rply....
I´ve read this and it´s very useful for begin with this. Thanks a lot
Thank you thank you thank you!
Thank you...after two days of fiddling around and numerous attempts on google i found your site with clear instructions...please keep up the good work.
Bayar
thnks alot
nice info.. Visit to my blog Okey..!!! Thanks!!
Hi Amit,
i am facing a problem,My database sever only open in window authentic mode because i don't know by default login password. Please tell me window authentication setting code in web config file.
amiT, thank you so very much! This article was just the thing I needed. I was having probs connection to my SQL database via LINQ and then iterating thru the entries to check if the user exists!!!!
Thank you so much!
Do you have a blog of you own? I wanna subscribe! thanks so much!!!!
i did read, it is very useful material
Thanks alot
Keep it up amit...good job.
All of your articles are very helpful.
Thanks for sharing your expertly
Mayuri
soooooooo sweet of you buddy....thanx a lot
thanx a lot.. u saved me from the hell
hi amit
its a brilliant kinda code
i tried it with my web application on XP, it works fine but in case of windows server it doesn't work at all....
can you help me ... ?
decent.cute.raja@gmail.com
Thank you so much for the post. One question if i may, when i publish my website everything works correctly, except folder permissions. Locally, all the folders are locked as specified in asp.net config, but after publish they are all available to any user role. any suggestions are much appreciated!!
how to get database "CustomMembership"
@rabindramajhi: Hi, you just need to create a empty database with any name in your sql server, i created a blank database with name customMembership for this example and used it
pharmacy technician jobs dallas texas http://exclusiverx.com/products/cytoxan.htm pharmacy benefit manager positions in san francisco
Thanks this was really helpful
Rethabile..
I just want make sure whether i did follow up the article. If i understand clearly you saying.
I must open my Sql Server Management Studio, create an empty database.
Command Prompt...
Configuration Page..Create User and Roles
So what i want to understand is, will this create the "User, Roles, Profile, UserGroup tables" as you find in aspnet built in database or i should create the table by myself first.
I just want make sure whether i follow up. What you said is that:
1. I Open my Sql Server Management Studio
2. Create an Empty database without tables
3. VS Command Prompt
4. Configuration Page
One other question is that will the tables like "Users, Roles, Profiles, UserGroup" be created automatically?
@Above : yes it will create all tables etc
Post a Comment