Click here to Skip to main content
15,881,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 forms 1st is login page and second is home page, I want to display user name and image on home page after he log in successful.

What I have tried:

this is my log in form
C#
protected void ValidateUser(object sender, EventArgs e)
{
    int userId = 0;
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("Validate_User"))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Username", Login1.UserName);
            cmd.Parameters.AddWithValue("@Password", Login1.Password);
            cmd.Connection = con;
            con.Open();
            userId = Convert.ToInt32(cmd.ExecuteScalar());
            con.Close();
        }
        switch (userId)
        {
            case -1:
                Login1.FailureText = "Username and/or password is incorrect.";
                break;
            case -2:
                Login1.FailureText = "Account has not been activated.";
                break;
            default:
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
                break;
        }
    }
}

and this is my home page
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.Page.User.Identity.IsAuthenticated)
    {
        FormsAuthentication.RedirectToLoginPage();
    }
}
Posted
Comments
Laxmidhar tatwa technologies 23-Jan-18 10:45am    
sir pl display storedprocedure
Gatsby29 23-Jan-18 10:58am    
USE [register]
GO
/****** Object: StoredProcedure [dbo].[Validate_User] Script Date: 23.1.2018. 16:58:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Validate_User]
@Email NVARCHAR(20),
@Password NVARCHAR(20)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @UserId INT, @LastLoginDate DATETIME

SELECT @UserId = UserId, @LastLoginDate = LastLoginDate
FROM Users WHERE Email = @Email AND [Password] = @Password

IF @UserId IS NOT NULL
BEGIN
IF NOT EXISTS(SELECT UserId FROM UserActivation WHERE UserId = @UserId)
BEGIN
UPDATE Users
SET LastLoginDate = GETDATE()
WHERE UserId = @UserId
SELECT @UserId [UserId] -- User Valid
END
ELSE
BEGIN
SELECT -2 -- User not activated.
END
END
ELSE
BEGIN
SELECT -1 -- User invalid.
END
END
Shashank Laxman 24-Jan-18 9:07am    
1)get the image
2)convert it to byte array and store it into database.
3)again read the image from database.
Laxmidhar tatwa technologies 23-Jan-18 11:05am    
insted of DECLARE @UserId INT, @LastLoginDate DATETIME

DECLARE @UserId INT
DECLARE @LastLoginDate DATETIME
Laxmidhar tatwa technologies 23-Jan-18 11:05am    
sir have to look and try in my pc .so I will convey later

thanks

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900