Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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)
                Response.Redirect("frmUserLogin.aspx");
            else if (Roles.IsUserInRole("Member"))
            {
                Response.Redirect("~/Protected/frmMemberHome.aspx");
            }
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 7:51am
Comments
Sandeep Mewara at 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 at 19-Apr-12 13:15pm
   
You have a response below from OP.
Just thought I'd let you know,
Ed
Sandeep Mewara at 19-Apr-12 14:26pm
   
Thanks Ed!
Jyoti Choudhury at 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
good
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[^].
  Permalink  
Comments
Espen Harlinn at 19-Apr-12 15:56pm
   
Good links, 5'ed!
Sandeep Mewara at 19-Apr-12 16:13pm
   
Thanks Espen.
Jyoti Choudhury at 20-Apr-12 23:42pm
   
thanks...
sravani.v at 21-Apr-12 0:20am
   
My 5!
Rate this: bad
good
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"))
             Response.Redirect("~/Protected/Member/frmMemberHome.aspx");
        else if (Roles.IsUserInRole(Login.UserName, "Admin"))
             Response.Redirect("~/Protected/Admin/frmAdminPanel.aspx");
}
 
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>
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server" xmlns:asp="#unknown">
    <asp:login id="Login" runat="server">
        DisplayRememberMe="False" OnLoggedIn="Login_LoggedIn"
</asp:login>
    </asp:content>
 
It works for me absolutely fine. Thanks a lot.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,488
1 OriginalGriff 6,516
2 Peter Leow 3,647
3 Zoltán Zörgő 3,416
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 20 Apr 2012
Copyright © CodeProject, 1999-2015
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