Membership.UserName Error - Security/Roles
-
Hi I cannot figure out why I get the error listed below with this chunk of code which is used with the ASP.NET 2 Login control. Error: ---------------------------------------------------------------- System.NullReferenceException: Object reference not set to an instance of an object. ASPUserUID = myMem.UserName; // Offendeding line Code: (This function runs when the user is authenticated) ---------------------------------------------------------------- protected void UserDetailsStore(object sender, EventArgs e) { global_functions gf = new global_functions(); string myUserName = User.Identity.Name; string ASPUserUID; MembershipUser myMem = Membership.GetUser(User.Identity.Name); ASPUserUID = myMem.UserName; } I've tried using ASPUserUID set as a Guid data type to no avail. ANy help in this regard would be greatly appreciated. John
-
Hi I cannot figure out why I get the error listed below with this chunk of code which is used with the ASP.NET 2 Login control. Error: ---------------------------------------------------------------- System.NullReferenceException: Object reference not set to an instance of an object. ASPUserUID = myMem.UserName; // Offendeding line Code: (This function runs when the user is authenticated) ---------------------------------------------------------------- protected void UserDetailsStore(object sender, EventArgs e) { global_functions gf = new global_functions(); string myUserName = User.Identity.Name; string ASPUserUID; MembershipUser myMem = Membership.GetUser(User.Identity.Name); ASPUserUID = myMem.UserName; } I've tried using ASPUserUID set as a Guid data type to no avail. ANy help in this regard would be greatly appreciated. John
Hi there, There are a couple of things that you might want to check: + Since you are using the Login control, so you need to make sure that the authentication
mode
in the web.config file is set toForms
. + You should only run your sample code after the user is successfully logged in. + You might want to check what is the value of the User.Identity.Name property. -
Hi there, There are a couple of things that you might want to check: + Since you are using the Login control, so you need to make sure that the authentication
mode
in the web.config file is set toForms
. + You should only run your sample code after the user is successfully logged in. + You might want to check what is the value of the User.Identity.Name property.Hi Thanks for your reply. Auth mode is set to forms already. The code sample shown runs on the Login control's "LoggedIn" event which is after a successful user authentication. The value of User.Identity.Name is coming through successfully as the user whom logged in.
-
Hi Thanks for your reply. Auth mode is set to forms already. The code sample shown runs on the Login control's "LoggedIn" event which is after a successful user authentication. The value of User.Identity.Name is coming through successfully as the user whom logged in.