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. if (Membership.GetUser() != null)

if (Membership.GetUser() != null)

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 4 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.
  • H Offline
    H Offline
    hurrem
    wrote on last edited by
    #1

    Hi, I can't understand, why this line is not working: if (Membership.GetUser() != null) Session.Add("current_user", Membership.GetUser().UserName); I used this code in my another program, and it works pretty good, but not in my new program. It is just never "true", even when the user is logging in. Do you know what's wrong? thanks

    S 1 Reply Last reply
    0
    • H hurrem

      Hi, I can't understand, why this line is not working: if (Membership.GetUser() != null) Session.Add("current_user", Membership.GetUser().UserName); I used this code in my another program, and it works pretty good, but not in my new program. It is just never "true", even when the user is logging in. Do you know what's wrong? thanks

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      1. Membership.GetUser() will only work for an authenticated user. Otherwise, it's going to return null. To verify you're dealing with an authenticated request call "User.Identity.IsAuthenticated" on the page. If you've got an authenticated request, but Membership.GetUser() is still returning null, then that means the username associated with the authenticated user can't be found in the Membership datasource. Verify the username of the authenticated user with "User.Identity.Name". 2. If you're calling one of the Membership.GetUser() overloads which takes the username and it's returning null, then that user doesn't exist in the Membership datasource (or we've got a bug). One way to easily verify this is to try a Membership.CreateUser() with the same username. If this doesn't throw an error because of a duplicate user, then you know the user never existed in the first place. 3. Membership.GetUser() should have never worked for an anonymous user. No support was built into Membership for handling this case. Hope this helps.

      SSK. Anyone who says sunshine brings happiness has never danced in the rain.

      N 1 Reply Last reply
      0
      • S Sathesh Sakthivel

        1. Membership.GetUser() will only work for an authenticated user. Otherwise, it's going to return null. To verify you're dealing with an authenticated request call "User.Identity.IsAuthenticated" on the page. If you've got an authenticated request, but Membership.GetUser() is still returning null, then that means the username associated with the authenticated user can't be found in the Membership datasource. Verify the username of the authenticated user with "User.Identity.Name". 2. If you're calling one of the Membership.GetUser() overloads which takes the username and it's returning null, then that user doesn't exist in the Membership datasource (or we've got a bug). One way to easily verify this is to try a Membership.CreateUser() with the same username. If this doesn't throw an error because of a duplicate user, then you know the user never existed in the first place. 3. Membership.GetUser() should have never worked for an anonymous user. No support was built into Membership for handling this case. Hope this helps.

        SSK. Anyone who says sunshine brings happiness has never danced in the rain.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Exactly copied from http://forums.asp.net/p/939408/1170831.aspx[^]

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        V 1 Reply Last reply
        0
        • N N a v a n e e t h

          Exactly copied from http://forums.asp.net/p/939408/1170831.aspx[^]

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          N a v a n e e t h wrote:

          Exactly copied from http://forums.asp.net/p/939408/1170831.aspx\[^\]

          Probably not. I see the following lines are different though: Source: Thanks, Mark This posting is provided "AS IS" with no warranties, and confers no rights. Destination: SSK.

          Vasudevan Deepak Kumar Personal Homepage
          Tech Gossips
          A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

          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