EnjoySharePoint YouTube Channel

Logging In Users Programmatically in Asp.Net

In this post, we will discuss how we can Logging in users programmatically in Asp.Net.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

Also, you can check out my previous posts on:

– ModalPopupExtender background CSS not coming when showing from code behind in asp.net

– Show confirmation dialog box using JavaScript in Asp.Net

– Data access block of Microsoft enterprise library 6.0 using a stored procedure

You can use pre-built mechanics of the Login control or you can also perform this task programmatically using the Membership class. To validate credentials that you receive, you use the ValidateUser() method of this class. The ValidateUser() method takes a single signature:

Membership.ValidateUser(username As String, password As String)

Validating a user’s credentials programmatically

In VB.net:

If Membership.ValidateUser(TextBox1.Text, TextBox2.Text) Then

FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, False)


Label1.Text = “You are not registered with the site.”

End If

In C#.net:

if (Membership.ValidateUser(TextBox1.Text, TextBox2.Text)


FormsAuthentication.RedirectFromLoginPage(TextBox1.Text.ToString(), false);




Label1.Text = “You are not registered with the site.”;


The ValidateUser() method returns a Boolean value of True if the user credentials pass the test and False if they do not.

you can see that end users whose credentials are verified as correct are redirected from the login page using the RedirectFromLoginPage() method. This method takes the username and a Boolean value that specifies whether the credentials are persisted through a cookie setting.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →