asp.net - get username after login -
i want username after login doesn't work.
public partial class login : system.web.ui.page { string struser; protected void login1_loggedin(object sender, eventargs e) { struser = membership.getuser().username; response.redirect("home"); } protected void login1_authenticate(object sender, authenticateeventargs e) { struser = membership.getuser().username; response.redirect("home"); } }
this error:
membership.getuser().username
null, because new principal object not attached current httpcontext object yet.
so need explicitly retrieve logged-in user using username login
control.
update: credit jadarnel27
protected void login1_authenticate(object sender, authenticateeventargs e) { // username login control , retrieves user info explicitly membership user = membership.getuser(login1.username); ... }
Comments
Post a Comment