Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.net login control to check user details using Membership concept

Jan 1, 2012
Introduction:

In this article I will explain how to use Login Control to validate user details using asp.net membership.

Description:

In previous post I explained clearly how to install asp.net membership database schema in SQL Server and create users using CreateUserWizard in asp.net membership. Here I am using these two concepts to validate user details with Login Control using asp.net membership in our login page.


In visual studio toolbox we have Login control in Login list section this control contain built in functionalities like validate username, password and check the user details against asp.net membership. We can use this control directly in login page instead of writing huge code in your login page with username, password textbox controls etc with asp.net membership database.

To install asp.net membership database schema in sql server check this post install membership database in SQL Server and to create user accounts check this post user accounts with CreateUserWizard.

After completion of database setup and user accounts creation open visual studio and create new web application after that right click on your application and Add new item select WebForm and give name as Login.aspx (If you want another name you can give another name also that is your wish). Now drag and drop the new control Login from Login Controls section into Login.aspx page after that check your aspx page code that would be like this


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Control to validate User Details</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Default.aspx">
</asp:Login>
</div>
</form>
</body>
</html>
Now open Default.aspx page drag and drop the Login status control and one label to our Default.aspx page will be like this 


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Control to validate User Details</title>
</head>
<body>
<form id="form1" runat="server">
<table align="center" width="200px">
<tr>
<td>
</td>
<td>
 <asp:LoginStatus ID="LoginStatus1" runat="server" />
</td>
</tr>
<tr>
<td><asp:Label ID="lblResult" runat="server" Font-Bold="true"/></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
Now write the following code in Default.aspx code behind to get login username

protected void Page_Load(object sender, EventArgs e)
{
lblResult.Text = "Welcome "+ Page.User.Identity.Name;
}
Now open Web.config file and change authentication mode to Forms and deny permissions for anonymous access

<authentication mode="Forms"/>
<authorization>
<deny users="?"/>
</authorization>
After that set database connection settings in web.config 

First set the connectionstring like this 

<connectionStrings>
<add name="dbconnection" connectionString="Data Source=SureshDasari;Initial Catalog=AspMembership;Integrated Security=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
After that write the following code in system.web section

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</roleManager>
Now run your application and check user credentials with asp.net membership database 

Demo


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

13 comments :

yes said...

good yaar

sunitha said...

goodmorning sir,can u help me on display videos in asp.net and c#

sunitha said...

sir,please give me code for how to display videos in asp.net

Anonymous said...

i've developed a asp.net(C#) project. i used one login control for 2 tables. ie. 1st table contains blood info details, 2nd table contains job info details. 2 tables have diff username and pwd to access their accounts.

The problem is how to separate which user belongs to which redirected page. here the admin also plays his role to login. so 3 logins in one login control.

someone send code r suggestion plz..

Anonymous said...

Comments are very negotiable for this gr8 helps
Thank you for all

Unknown said...

Hi I need one urgent help..Pls tell me how to reboot the another server using that user authentication detail in ur own asp.net web application.

Help said...

Give me one example on Form based example.........

sai said...

really helpful to dotnet students

Unknown said...

how to download coding please tellme

Unknown said...

how to connect to the administative property in login control

Anonymous said...

Your all blogs are very clear to understand.
Thank you.

nitika said...

hi .. i want to make a login page . and on clicking the login button futher it shows details of that particular student from table in textbox... help me it urgent

Anonymous said...

nice

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.