Click here to Skip to main content
12,953,937 members (46,888 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am new in ASP.NET and I am facing problem using Login Control that is built-in with ASP.NET.

I want to build an web application that has login control. I used ASP.NET Configuration wizard to setup the login authentication config. I have created 2 users and 2 roles allready, but the problem is, I can not login using the username/password of the user allready created in the database.

I have following code written in Login_Authenticate event:

if (User.Identity.IsAuthenticated == false)
            else if (Roles.IsUserInRole("Member"))

First if condition refers to the situation when authentication fails else I have checked for the roles in which my user is included. Based on their roles, I have redirected them to different pages. That is all my plan to evaluate.

Problem is each time I am trying to login using correct username/password for existing user, it fails and shows error messages for Authentication Failure. I don't have any idea. I dont know, If I am doing wrong or not! Please help me out!
Posted 19-Apr-12 6:51am
Sandeep Mewara 19-Apr-12 12:58pm
Where/which part of the code you are authenticating here?

The above code lines just check if authenticated or not - its a step after verification of authentication using username/password.
Ed Nutting 19-Apr-12 13:15pm
You have a response below from OP.
Just thought I'd let you know,
Sandeep Mewara 19-Apr-12 14:26pm
Thanks Ed!
Jyoti Choudhury 19-Apr-12 13:02pm
But, each time login fails and a failure message is displayed. But as long as username/password is correct then it should validate and set the isAuthenticated to True...If I am wrong, can you please give me solution how to solve!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Look here:
Traditional Login page design discussion[^]

Login Controls were released by Microsoft, have a look at them here[^].
For, building Login Page using Login control, look:
How to: Create an ASP.NET Login Page[^]
ASP.NET Login Controls Overview[^]
How to add a Login, Roles and Profile system to an ASP.NET 2.0 [^]

If needed, pick any example from here: Google Search result on the same[^].
Espen Harlinn 19-Apr-12 15:56pm
Good links, 5'ed!
Sandeep Mewara 19-Apr-12 16:13pm
Thanks Espen.
Jyoti Choudhury 20-Apr-12 23:42pm
sravani.v 21-Apr-12 0:20am
My 5!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I have tried several times and I came to the point that this problem occurs only when I put the code in Login.Authenticate event. From MSDN, it's almost clear that Authenticate event raises when user use Login control to log into the system. The main objective of this event is to perform any tasks while checking the user for authentication.

So,I tried Login.LoggedIn event that raises just after the Login.Authenticate event. LoggedIn event is responsible for any tasks that is needed to perform after validation (e.g. Accessing to the per-user data, redirecting user to different pages etc.)

For my case, I need LoggedIn event, So I tried the following code:

frmUserLogin.aspx.cs File:

//code behind file

protected void Login_LoggedIn(object sender, EventArgs e)
        if (Roles.IsUserInRole(Login.UserName, "Member"))
        else if (Roles.IsUserInRole(Login.UserName, "Admin"))

HTML Code for frmUserLogin.aspx

<![CDATA[<%@ Page Title="" Language="C#" MasterPageFile="~/mainLayout.Master" AutoEventWireup="true" CodeBehind="frmUserLogin.aspx.cs" Inherits="OnlineTMS_MIST.frmUserLogin" %>
<asp:content id="Content1" contentplaceholderid="head" runat="server" xmlns:asp="#unknown">
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server" xmlns:asp="#unknown">
    <asp:login id="Login" runat="server">
        DisplayRememberMe="False" OnLoggedIn="Login_LoggedIn"

It works for me absolutely fine. Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 20 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100