Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my login aspx code

C#
<asp:TextBox ID="TextBox1" runat="server">

    <asp:TextBox ID="TextBox2" runat="server">

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    <asp:Label ID="Label1" runat="server" Text="Label">


it's mine login cs code

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        int cnt = 0;

        SqlDataAdapter ad1 = new SqlDataAdapter(@"select Id  from UserReg WHERE Name='" + TextBox1.Text + "' AND Password='" + TextBox2.Text + "'", con);
        DataTable dt = new DataTable();
        ad1.Fill(dt);
         cnt = Convert.ToInt32(dt.Rows[0]["Id"]);

         if (cnt > 0)
         {
             Response.Redirect("profile.aspx?id=" + cnt); //Response.Redirect("page.aspx?id=" + cnt);
         }

         else
         {
             Label1.Text = "Invalid username or password";
             this.Label1.ForeColor = Color.Red;
         }
        
       
    }

after login how to redirect to the user profile page>>? help me plz and how to use [session and cookies] for this code
Posted
Updated 13-Apr-14 8:31am
v2
Comments
Manas Bhardwaj 13-Apr-14 14:34pm    
Haven't you already done redirection? Or I am missing something?
Bajpangosh 13-Apr-14 14:37pm    
yes i did but after login it's does not redirect to the proper profile :(

1 solution

First of all, don't use inline queries like this. This leads to SQL Injection attack. Use Parameterized queries instead.

No need to use DataAdapter, as you are reading only one value. You can use DataReader.
Then debug your code and see what is happening. You have already coded for redirection. Isn't it working?

To store values in Session, you can do like...
C#
Session["SomeName"] = "someValue";
 
Share this answer
 
Comments
Bajpangosh 13-Apr-14 14:41pm    
yes it's working bro but it's does't show the logged user profile :(
That is a different issue. You need to debug the profile.aspx page code and see what is happening.

Happy coding. :)
Bajpangosh 13-Apr-14 14:50pm    
i didn't get you. after successful login how to redirect the logged user profile any ideas>?
It is already redirecting as you have coded for that.

The following line should do the redirection.

Response.Redirect("profile.aspx?id=" + cnt);
Bajpangosh 13-Apr-14 22:13pm    
thx but it's shows a blank page

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