I have this code

protected void loginbutton_Click(object sender, EventArgs e)
    {
        Int32 d = checkuser(uid.Text, pwd.Text);
        if (d == -1)
        {
            prompt.Visible = true;
            prompt.Text = "Unregistered ID. Please make sure that you have a registered account and you have correctly typed in the user ID";
        }
        else if (d == 1)
        {
            Server.Transfer("Enrollment.aspx");
        }
        else if (d == -2)
        {
            prompt.Visible = true;
            prompt.Text = "Incorrect password. Please try again.";
        }
    }

    private Int32 checkuser(string u, string p)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_checkuser";
        cmd.Connection = con;
        cmd.Parameters.Add("@uid", SqlDbType.NVarChar).Value = uid.Text;
        cmd.Parameters.Add("@pwd", SqlDbType.NVarChar).Value = pwd.Text;
        SqlParameter p1 = new SqlParameter("@ret", SqlDbType.Int);
        p1.Direction = ParameterDirection.ReturnValue;
        cmd.Parameters.Add(p1);
        con.Open();
        cmd.ExecuteNonQuery();
        Int32 k = Convert.ToInt32(cmd.Parameters["@ret"].Value);
        return k;
    }

for transferring the user to the desired page when he/she login. What I need to do is the logout. The user must not be able to go back to the previous page when he/she choose to logout.

Member Avatar for siju kuriakose

Hi,
One method-create a session variable and store the userid and check it exist on page load event of every page.On logout click, clear the session variable and redirect to login page.
Hope your reply

It's my first time to create a session variable. How to do it?

Member Avatar for siju kuriakose

Hi,
Assign:-
Session["uid"]=str_uid;
Retrieve:-
string id=Session["uid"].ToString();
Checking:-
if(Session["uid"]!=Null)
{
}
hope ur reply

clear all the session variables
and simply disable the cache of the page

you can do this using code or in the markup.
or you can use server.transfer

hope that helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.