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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Membership.UserName Error - Security/Roles

Membership.UserName Error - Security/Roles

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netsecurity
4 Posts 2 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.
  • Z Offline
    Z Offline
    zanzibarwinds
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • Z zanzibarwinds

      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

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      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 to Forms. + 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.

      Z 1 Reply Last reply
      0
      • M minhpc_bk

        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 to Forms. + 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.

        Z Offline
        Z Offline
        zanzibarwinds
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • Z zanzibarwinds

          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.

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          You may try to check the myMem object before using it as below:

          ASPUserUID = (myMem!=null)? myMem.UserName : "";

          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