newbie: check if user is a anonymous user

Discussion in 'ASP .Net' started by Jeff, Jul 9, 2006.

  1. Jeff

    Jeff Guest

    hey

    asp.net 2.0

    How can I from the code check if a user is a anonymous user or a loggedin
    user...

    I guess there must be a better way of doing it than this:
    if (Profile.UserName == null) {
    //user is anonymous
    }

    I have a loginview in my webpage, maybe the loginview have some methods or
    properties for this... I need to know how to check this from the code
    page...... .cs files

    Any suggestions?

    Jeff
    Jeff, Jul 9, 2006
    #1
    1. Advertising

  2. Jeff

    PeterKellner Guest

    On Sun, 9 Jul 2006 17:56:24 +0200, "Jeff"
    <> wrote:

    >hey
    >
    >asp.net 2.0
    >
    >How can I from the code check if a user is a anonymous user or a loggedin
    >user...
    >
    >I guess there must be a better way of doing it than this:
    >if (Profile.UserName == null) {
    > //user is anonymous
    >}
    >
    >I have a loginview in my webpage, maybe the loginview have some methods or
    >properties for this... I need to know how to check this from the code
    >page...... .cs files
    >
    >Any suggestions?
    >
    >Jeff
    >


    How about this:

    IPrincipal iPrincipal = HttpContext.Current.User;
    if (iPrincipal.Identity.IsAuthenticated)
    {
    authenticated = true;
    ...
    Peter Kellner
    http://peterkellner.net
    PeterKellner, Jul 9, 2006
    #2
    1. Advertising

  3. I think you missed the IsAnonymous property of the Profile Class.
    Cheers,
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Jeff" wrote:

    > hey
    >
    > asp.net 2.0
    >
    > How can I from the code check if a user is a anonymous user or a loggedin
    > user...
    >
    > I guess there must be a better way of doing it than this:
    > if (Profile.UserName == null) {
    > //user is anonymous
    > }
    >
    > I have a loginview in my webpage, maybe the loginview have some methods or
    > properties for this... I need to know how to check this from the code
    > page...... .cs files
    >
    > Any suggestions?
    >
    > Jeff
    >
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jul 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maellic
    Replies:
    3
    Views:
    4,304
    Maellic
    Jan 13, 2004
  2. Reporter
    Replies:
    3
    Views:
    469
    Mike Schilling
    May 12, 2007
  3. JB
    Replies:
    1
    Views:
    547
  4. R.A.M.

    2.0: newbie: anonymous access and IUSR_ account

    R.A.M., Nov 8, 2006, in forum: ASP .Net Security
    Replies:
    4
    Views:
    230
    Master Programmer
    Nov 16, 2006
  5. Replies:
    1
    Views:
    218
Loading...

Share This Page