Results 1 to 9 of 9

Thread: Context.User.Identity.Name is empty value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    Context.User.Identity.Name is empty value

    Dear ..

    How to get the use login value after succssful login.
    I am assigning Context.User.Identity.Name to the variable but the context.user has empty value.
    can any body help me what settings need to done so that I will get Context.User.Identity.Name value.

    Help is expected and appreciated..


    Thanks & Regsrds


    PPCC

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    Are you using formsauthentication?
    if so user.identity.name should work no problem.
    Try running
    VB Code:
    1. if user.Identity.IsAuthenticated then
    2.     'Do something here
    3. end if
    first to check that authCookie has been properly set.

    Failing that could you post your login code?

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Try HttpContext.Current.User.Identity.Name

    which is just what Fishcake said to do.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    forms authentication

    yes I am doing formsauthentication, now how to set authcookie.Is it auto set.
    how context.user.identity.name relates with application_authenticateRequest event in golbal.asax .

    reply..

    PPCC

  5. #5
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    There's a couple of ways you can set the AuthCookie.

    1.
    VB Code:
    1. FormsAuthentication.SetAuthCookie(intPlayerID, False)
    Where intPlayerID is actually a string that uniquely identify's your user and true/false states wether the cookie is persistent.
    2.
    VB Code:
    1. FormsAuthentication.RedirectFromLoginPage(intPlayerID, False)
    This method can be used to redirect a user back to a page they were trying to visit before they were authenticated, same parameters as above.

    Be warned that if you use the second method and directly enter the address of the login page you will simply keep getting taken back to it.

    After either of these methods user.identity.name will hold the value of your user in my case intPlayerID.


    As for application_authenticateRequest i've never actually used it but i'd guess it fires when a user tries to visit a page of your site that requires authentication (please tell me if i wrong), so you shouldn't need to worry about that for now.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    form authentication

    Great..

    I have tried second option
    i.e

    .RedirectFromLoginPage("Id",false)

    but after that Context.User.Identity.Name is getting empty.

    can u please help me.

    Thanks

    PPCC

  7. #7
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    I'm not actually sure what difference context makes but i have simply always used "user.identity.name".

    Other than that the only reason i can see for that being empty is if "id" is empty to start with.

  8. #8
    Lively Member
    Join Date
    May 2004
    Location
    London
    Posts
    107

    Re: Context.User.Identity.Name is empty value

    I am having the same problem, did you ever solve this?

  9. #9
    Addicted Member Rockhopper's Avatar
    Join Date
    Aug 2003
    Location
    Cape Town, South Africa
    Posts
    199

    Re: Context.User.Identity.Name is empty value

    Had the same issue.. used all of the above... ended up making my own cookie with encryption for the username etc

    Couldn't use the session cos i think my hosting hasn't got their webfarm working propery.. session gets lost sometimes and appears again
    If the facts don't fit the theory, change the facts. --Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width