Friday, June 12, 2009

ASP.NET Login Control with custom membership provider database


If you want to use Login Control of ASP.NET with Custom DataBase and custom membership Provider 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
 
 Choose your Database Server and DataBase Name 

Now open web.config file and write below mentioned code 
Add connection string
<connectionStrings>
    <add name="ConnectionString" 
    connectionString="server=AVDHESH\SQLEXPRESS;
    database=CustomMembership;uid=amit;password=password;"/>    
  </connectionStrings>
Now add this code in System.web section of web.config
<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 
www.tips-fb.com
Shout it
Stumble Upon Toolbar
Submit this story to DotNetKicks vote it on WebDevVote.com add to del.icio.us saved by 0 users
Subscribe to Feeds

8 comments:

Anonymous said...

You can't believe how much you just helped me. Thanks you so much.


Anonymous said...

hey amit,
thanks.
u saved many hours of mine.


Abhishek Singh said...

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


amiT
amiT jaiN said...

@abhishek Singh:

Please check the connection string in Your web.config file under membership defaultProvider="CustomMembershipProvider" section


Sean Olson said...

Hi Amit,

Thanks for breaking this down so nicely. I book-marked you on Stumble and Digg. Good work!

Sean


amiT
amiT jaiN said...

@Sean Olson:

Thanks a lot for the appreciation and favor :)

Keep visiting


Anonymous said...

thanks amit!
i will sleep today properly after
one week .
thnks again

uzz


Anonymous said...

good looking


About Me

My Photo
amiT jaiN
Hi, I am amiT jaiN Software engineer working on C#.NET and ASP.NET technologies
View my complete profile

Comments

.NET Resources

Find More Articles


Subscribe To Feeds

Subscribe by E-mail

Enter your email address:

Delivered by FeedBurner


Subscribe in your favorite reader

This site is best viewed with || You may get errors in proper display of this site if using Internet explorer


C#.NET Articles and tutorials,ASP.NET Articles - blog by amiT jaiN