Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Display LoginName from LoginControl

Display LoginName from LoginControl

Scheduled Pinned Locked Moved C#
helpdatabasetutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SharonRao
    wrote on last edited by
    #1

    Hello All, I have a web page with login control binded to custom sql membershipProvider to authorise the user. I was trying to use GetUser() method to display username but it is giving an error, I think i need to override Membership.GetUser() method as well becos i understand its not using my custom SQL membership provider to get the loginname but iam stuck dont know how to acheive that. can someone help me out here, please see code below. Login.aspx.cs protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { bool Authenticated = false; Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password); e.Authenticated = Authenticated; if (Authenticated == true) { Response.Redirect( "Welcome.aspx"); } } private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password) { System.Data.SqlClient. SqlConnection Con = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); System.Data.SqlClient. SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(); Cmd.Connection = Con; Cmd.CommandType = CommandType.StoredProcedure; try { Con.Open(); Cmd.CommandText = "name"; Cmd.Parameters.Add( "@UserName", SqlDbType.VarChar, 20); Cmd.Parameters[ "@UserName"].Value = UserName; Cmd.Parameters.Add( "@Password", SqlDbType.VarChar, 20); Cmd.Parameters[ "@Password"].Value = Password; System.Data.SqlClient. SqlDataReader reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) { return true; } else { return false; } } catch (Exception ex) { Console.WriteLine(ex.Message); //Return False; } throw new Exception("The method or operation is not implemented."); } Welcome.aspx.cs (After user logs in he is redirected to this page) protected void Page_Load(object sender, EventArgs e) { MembershipUser CurrentUser = Membership.GetUser(true); [This gives me an error ] Label1.Text = CurrentUser.UserName.ToString(); }

    Thanks in Advance for your help. Best Regards

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups