Akhter HUssain

Akhter HUssain

  • 720
  • 1.3k
  • 102.1k

Session id redirect issue

May 1 2020 4:46 AM
i have login form,in which i am loggin from User Name and password ,at the befhalf of user name and password i am retreiving user id in session,but when page is redirect then just first ID of table is being retreived every time.
 
below is c# code 
  1. using (SqlCommand cmd = new SqlCommand("Validate_User"))  
  2.           {  
  3.   
  4.   
  5.               cmd.CommandType = CommandType.StoredProcedure;  
  6.               cmd.Parameters.AddWithValue("@Username", username.Text.Trim());  
  7.               cmd.Parameters.AddWithValue("@Password", password.Text.Trim());  
  8.               cmd.Connection = con;  
  9.               con.Open();  
  10.               SqlDataAdapter sda = new SqlDataAdapter(cmd);  
  11.               DataTable dt = new DataTable();  
  12.               sda.Fill(dt);  
  13.               if (dt.Rows.Count > 0)  
  14.               {  
  15.                   // lblmsg.Text = "Login Successful";  
  16.                   Session["S_ID"] = dt.Rows[0]["S_ID"].ToString();  
  17.             
  18.                   Response.Redirect("issue_std_Books.aspx");  
  19.               }  
  20.               else  
  21.               {  
  22.                   // lblmsg.Text = "Invalid UserName/Password";  
  23.               }  
  24.               con.Close();  
  25.               con.Dispose();  
  26.           }  
  27.       }  
SQl store procedure
 
  1. ALTER PROCEDURE [dbo].[Validate_User]  
  2. @Username NVARCHAR(20),  
  3.       @Password NVARCHAR(20)  
  4. AS  
  5. BEGIN  
  6.       SET NOCOUNT ON;  
  7.       DECLARE @UserId INT  
  8.          
  9.       SELECT @UserId = S_ID  
  10.       FROM tbl_Student WHERE [S_Name] = @Username AND t_pwd = @Password  
  11.      
  12.       IF @UserId  IS NOT NULL  
  13.       BEGIN  
  14.             SELECT S_ID FROM tbl_Student  
  15.       END  
  16.       end  
 

Answers (3)