Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

How do i get username of a user after logging

$
0
0

How do i get username of a user after logging

if (!this.Page.User.Identity.IsAuthenticated)
    {
        FormsAuthentication.RedirectToLoginPage();
    }

        }

And i also want to use session on other pages to get username

This is my login

protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
    {

        int userId = 0;
        string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("Validat_UserTable"))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@UserName", ctlLogin.UserName);
                cmd.Parameters.AddWithValue("@Password", ctlLogin.Password);
                cmd.Connection = con;
                con.Open();
                userId = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
            }
            switch (userId)
            {
                case -1:
                    ctlLogin.FailureText = "Username and/or password is incorrect.";
                    break;
                case -2:
                    ctlLogin.FailureText = "Account has not been activated.";
                    break;
                default:
                    FormsAuthentication.RedirectFromLoginPage(ctlLogin.UserName, ctlLogin.RememberMeSet);
                    break;
            }

This is the page that i want to use session

protected void Page_Load(object sender, EventArgs e)
    {
      //  btnCancel.Visible = false;
        if (!Page.IsPostBack)
        {
            if (!Page.IsPostBack)
            {
                //GetUserProfile2(int.Parse(Request.QueryString["Id"].ToString()));
            }
        }
    }
    public void GetUserProfile2(int Id)
    {


        string str = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
        string getADPOST = "GetUSERPROFILE1";
        using (SqlConnection con = new SqlConnection(str))
        {
            con.Open();
            using (SqlCommand cmd = new SqlCommand(getADPOST, con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Id", Request.QueryString["Id"].ToString());
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);



                userprofile.DataSource = ds;
                userprofile.DataBind();
                {

                   


Viewing all articles
Browse latest Browse all 4737

Trending Articles