User.Identity.Name returns nothing / NULL

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default User.Identity.Name returns nothing / NULL

    Hi
    I have created two pages, the login.aspx and the formA.aspx, and each of
    this has a corresponding *.cs files for code separation

    the scenario is, I seems to be able to login / authenticated because
    formA.aspx got loaded. But when I added the following lines
    Label1.Text = HttpContext.Current.User.Identity.Name;

    to the Page_Load event under FormA.cs, the control Label1 simply not showing
    anything!

    Do I need to do anything to get the "User.Identity.Name" set? (in config
    files and / or after successful login)?
    What is the problem here, please?

    TIA
    ____
    username and password collected by login.aspx is authenticated against the
    AD with LDAP using the following code
    //
    DirectoryEntry entry = new DirectoryEntry(strPath, uName, pwd);
    try
    {
    // Bind to the native object to force authentication to happen
    Object obj = entry.NativeObject;
    }
    catch (Exception ex)
    {
    throw new Exception("User authentication failed: " +
    ex.Message);
    }

    Server.Transfer("formA.aspx");
    _______
    formA.aspx contains a form for user to fill out some information.
    --



    Guest

  2. Similar Questions and Discussions

    1. ASP.NET User.Identity.Name returns wrong value?
      When I got Visual Studio setup and configured to remotely debug c# ASP.NET applications on a development IIS server I apparently changed something...
    2. #26132 [Bgs]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      ID: 26132 User updated by: steven at pearavenue dot com Reported By: steven at pearavenue dot com Status: Bogus Bug...
    3. #26132 [Opn->Bgs]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      ID: 26132 Updated by: iliaa@php.net Reported By: steven at pearavenue dot com -Status: Open +Status: ...
    4. #26132 [Opn]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      ID: 26132 User updated by: steven at pearavenue dot com Reported By: steven at pearavenue dot com Status: Open Bug...
    5. #26132 [NEW]: pg_fetch_object returns NULL on serial and INT in record but returns strings NP
      From: steven at pearavenue dot com Operating system: Redhat 9.0/Apache 2.0 PHP version: 4.3.4 PHP Bug Type: PostgreSQL...
  3. #2

    Default Re: User.Identity.Name returns nothing / NULL

    Hello dl,

    makes sure you are really authenticated - IIS is LBD (lazy by default). Go
    the the directory security tab and clear "anonymous login" for the virtual
    directory.

    ---------------------------------------
    Dominick Baier - DevelopMentor
    [url]http://www.leastprivilege.com[/url]
    > Hi
    > I have created two pages, the login.aspx and the formA.aspx, and each
    > of
    > this has a corresponding *.cs files for code separation
    > the scenario is, I seems to be able to login / authenticated because
    > formA.aspx got loaded. But when I added the following lines
    > Label1.Text = HttpContext.Current.User.Identity.Name;
    > to the Page_Load event under FormA.cs, the control Label1 simply not
    > showing anything!
    >
    > Do I need to do anything to get the "User.Identity.Name" set? (in
    > config
    > files and / or after successful login)?
    > What is the problem here, please?
    > TIA
    > ____
    > username and password collected by login.aspx is authenticated against
    > the
    > AD with LDAP using the following code
    > //
    > DirectoryEntry entry = new DirectoryEntry(strPath, uName,
    > pwd);
    > try
    > {
    > // Bind to the native object to force authentication to
    > happen
    > Object obj = entry.NativeObject;
    > }
    > catch (Exception ex)
    > {
    > throw new Exception("User authentication failed: " +
    > ex.Message);
    > }
    > Server.Transfer("formA.aspx");
    > _______
    > formA.aspx contains a form for user to fill out some information.


    Dominick Baier [DevelopMentor] Guest

  4. #3

    Default Re: User.Identity.Name returns nothing / NULL

    Hello dl,

    ah - ok - if you are doing custom authentication - you have to construct
    an IPrincipal object yourself -

    have a look at GenericPrincipal and AuthenticateRequest in the docs.

    Basically you have to construct that Principal object in the AuthenticateRequest
    event and attach it to Context.User, like

    Context.User = new GenericPrincipal(new GenericIdentity(..), roles);

    ---------------------------------------
    Dominick Baier - DevelopMentor
    [url]http://www.leastprivilege.com[/url]
    > Hi
    > I have created two pages, the login.aspx and the formA.aspx, and each
    > of
    > this has a corresponding *.cs files for code separation
    > the scenario is, I seems to be able to login / authenticated because
    > formA.aspx got loaded. But when I added the following lines
    > Label1.Text = HttpContext.Current.User.Identity.Name;
    > to the Page_Load event under FormA.cs, the control Label1 simply not
    > showing anything!
    >
    > Do I need to do anything to get the "User.Identity.Name" set? (in
    > config
    > files and / or after successful login)?
    > What is the problem here, please?
    > TIA
    > ____
    > username and password collected by login.aspx is authenticated against
    > the
    > AD with LDAP using the following code
    > //
    > DirectoryEntry entry = new DirectoryEntry(strPath, uName,
    > pwd);
    > try
    > {
    > // Bind to the native object to force authentication to
    > happen
    > Object obj = entry.NativeObject;
    > }
    > catch (Exception ex)
    > {
    > throw new Exception("User authentication failed: " +
    > ex.Message);
    > }
    > Server.Transfer("formA.aspx");
    > _______
    > formA.aspx contains a form for user to fill out some information.


    Dominick Baier [DevelopMentor] Guest

  5. #4

    Default Re: User.Identity.Name returns nothing / NULL

    Hi Dominick
    I think this is the problem, and I found the following link under MS
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/active_directory_authentication_from_ASP__Net.asp[/url]
    has an example using code behind with VS.Net, the problem is I am only using
    Web Matrix / VWD 2005 Express. I am trying to put the Global.asax code in a
    class using <@page ... inherits=...>, but there is one line I am having
    problem with, can you help, please?

    HttpCookie authCookie = Context.Request.Cookies[cookieName];

    on compiling the class, I am getting the following error
    The type or namespace "Context" could not be found (are you missing a using
    directive or an assembly reference?)

    by the way, can you give me the link to the docs on AuthenticateRequest /
    GenericPricipal?
    Is there any other good example on Form authentication along with the
    required Global.asax file?

    TIA


    "Dominick Baier [DevelopMentor]" <dbaier@pleasepleasenospamdevelop.com>
    wrote in message news:364328632512174720446016@news.microsoft.com.. .
    > Hello dl,
    >
    > ah - ok - if you are doing custom authentication - you have to construct
    > an IPrincipal object yourself -
    >
    > have a look at GenericPrincipal and AuthenticateRequest in the docs.
    >
    > Basically you have to construct that Principal object in the
    AuthenticateRequest
    > event and attach it to Context.User, like
    >
    > Context.User = new GenericPrincipal(new GenericIdentity(..), roles);
    >
    > ---------------------------------------
    > Dominick Baier - DevelopMentor
    > [url]http://www.leastprivilege.com[/url]
    >
    > > Hi
    > > I have created two pages, the login.aspx and the formA.aspx, and each
    > > of
    > > this has a corresponding *.cs files for code separation
    > > the scenario is, I seems to be able to login / authenticated because
    > > formA.aspx got loaded. But when I added the following lines
    > > Label1.Text = HttpContext.Current.User.Identity.Name;
    > > to the Page_Load event under FormA.cs, the control Label1 simply not
    > > showing anything!
    > >
    > > Do I need to do anything to get the "User.Identity.Name" set? (in
    > > config
    > > files and / or after successful login)?
    > > What is the problem here, please?
    > > TIA
    > > ____
    > > username and password collected by login.aspx is authenticated against
    > > the
    > > AD with LDAP using the following code
    > > //
    > > DirectoryEntry entry = new DirectoryEntry(strPath, uName,
    > > pwd);
    > > try
    > > {
    > > // Bind to the native object to force authentication to
    > > happen
    > > Object obj = entry.NativeObject;
    > > }
    > > catch (Exception ex)
    > > {
    > > throw new Exception("User authentication failed: " +
    > > ex.Message);
    > > }
    > > Server.Transfer("formA.aspx");
    > > _______
    > > formA.aspx contains a form for user to fill out some information.
    >
    >
    >

    Guest

  6. #5

    Default Re: User.Identity.Name returns nothing / NULL

    Hello dl,

    there is a sample on my blog which shows you how do this:
    [url]http://www.leastprivilege.com/PermaLink.aspx?guid=b0e51388-71d1-4a6f-98d0-bc8cfbec4c3a[/url]

    btw - you can always get a context by calling:

    HttpContext context = HttpContext.Current;

    feel free to ask if you have any questions

    HTH
    ---------------------------------------
    Dominick Baier - DevelopMentor
    [url]http://www.leastprivilege.com[/url]
    > Hi Dominick
    >
    > I think this is the problem, and I found the following link under MS
    >
    > [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/s[/url]
    > ds/active_directory_authentication_from_ASP__Net.asp
    >
    > has an example using code behind with VS.Net, the problem is I am only
    > using
    >
    > Web Matrix / VWD 2005 Express. I am trying to put the Global.asax
    > code in a
    >
    > class using <@page ... inherits=...>, but there is one line I am
    > having
    >
    > problem with, can you help, please?
    >
    > HttpCookie authCookie = Context.Request.Cookies[cookieName];
    >
    > on compiling the class, I am getting the following error
    > The type or namespace "Context" could not be found (are you missing a
    > using
    > directive or an assembly reference?)
    > by the way, can you give me the link to the docs on
    > AuthenticateRequest /
    > GenericPricipal?
    > Is there any other good example on Form authentication along with the
    > required Global.asax file?
    > TIA
    >
    > "Dominick Baier [DevelopMentor]"
    > <dbaier@pleasepleasenospamdevelop.com> wrote in message
    > news:364328632512174720446016@news.microsoft.com.. .
    >
    >> Hello dl,
    >>
    >> ah - ok - if you are doing custom authentication - you have to
    >> construct an IPrincipal object yourself -
    >>
    >> have a look at GenericPrincipal and AuthenticateRequest in the docs.
    >>
    >> Basically you have to construct that Principal object in the
    >>
    > AuthenticateRequest
    >
    >> event and attach it to Context.User, like
    >>
    >> Context.User = new GenericPrincipal(new GenericIdentity(..), roles);
    >>
    >> ---------------------------------------
    >> Dominick Baier - DevelopMentor
    >> [url]http://www.leastprivilege.com[/url]
    >>> Hi
    >>> I have created two pages, the login.aspx and the formA.aspx, and
    >>> each
    >>> of
    >>> this has a corresponding *.cs files for code separation
    >>> the scenario is, I seems to be able to login / authenticated because
    >>> formA.aspx got loaded. But when I added the following lines
    >>> Label1.Text = HttpContext.Current.User.Identity.Name;
    >>> to the Page_Load event under FormA.cs, the control Label1 simply not
    >>> showing anything!
    >>> Do I need to do anything to get the "User.Identity.Name" set? (in
    >>> config
    >>> files and / or after successful login)?
    >>> What is the problem here, please?
    >>> TIA
    >>> ____
    >>> username and password collected by login.aspx is authenticated
    >>> against
    >>> the
    >>> AD with LDAP using the following code
    >>> //
    >>> DirectoryEntry entry = new DirectoryEntry(strPath, uName,
    >>> pwd);
    >>> try
    >>> {
    >>> // Bind to the native object to force authentication to
    >>> happen
    >>> Object obj = entry.NativeObject;
    >>> }
    >>> catch (Exception ex)
    >>> {
    >>> throw new Exception("User authentication failed: " +
    >>> ex.Message);
    >>> }
    >>> Server.Transfer("formA.aspx");
    >>> _______
    >>> formA.aspx contains a form for user to fill out some information.


    Dominick Baier [DevelopMentor] Guest

  7. #6

    Default Re: User.Identity.Name returns nothing / NULL

    Hi Dominick
    Thankyou very much.

    In fact, I just experience a problem with the formA.aspx / formA.cs and post
    another thread on newsgroup microsoft.public.dotnet.framework.aspnet, wonder
    if you spare some time to take a look and advice on that also ?!

    TIA

    "Dominick Baier [DevelopMentor]" <dbaier@pleasepleasenospamdevelop.com>
    wrote in message news:366402632512610278910960@news.microsoft.com.. .
    > Hello dl,
    >
    > there is a sample on my blog which shows you how do this:
    >
    [url]http://www.leastprivilege.com/PermaLink.aspx?guid=b0e51388-71d1-4a6f-98d0-bc8cfbec4c3a[/url]
    >
    > btw - you can always get a context by calling:
    >
    > HttpContext context = HttpContext.Current;
    >
    > feel free to ask if you have any questions
    >
    > HTH
    > ---------------------------------------
    > Dominick Baier - DevelopMentor
    > [url]http://www.leastprivilege.com[/url]
    >
    > > Hi Dominick
    > >
    > > I think this is the problem, and I found the following link under MS
    > >
    > > [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/s[/url]
    > > ds/active_directory_authentication_from_ASP__Net.asp
    > >
    > > has an example using code behind with VS.Net, the problem is I am only
    > > using
    > >
    > > Web Matrix / VWD 2005 Express. I am trying to put the Global.asax
    > > code in a
    > >
    > > class using <@page ... inherits=...>, but there is one line I am
    > > having
    > >
    > > problem with, can you help, please?
    > >
    > > HttpCookie authCookie = Context.Request.Cookies[cookieName];
    > >
    > > on compiling the class, I am getting the following error
    > > The type or namespace "Context" could not be found (are you missing a
    > > using
    > > directive or an assembly reference?)
    > > by the way, can you give me the link to the docs on
    > > AuthenticateRequest /
    > > GenericPricipal?
    > > Is there any other good example on Form authentication along with the
    > > required Global.asax file?
    > > TIA
    > >
    > > "Dominick Baier [DevelopMentor]"
    > > <dbaier@pleasepleasenospamdevelop.com> wrote in message
    > > news:364328632512174720446016@news.microsoft.com.. .
    > >
    > >> Hello dl,
    > >>
    > >> ah - ok - if you are doing custom authentication - you have to
    > >> construct an IPrincipal object yourself -
    > >>
    > >> have a look at GenericPrincipal and AuthenticateRequest in the docs.
    > >>
    > >> Basically you have to construct that Principal object in the
    > >>
    > > AuthenticateRequest
    > >
    > >> event and attach it to Context.User, like
    > >>
    > >> Context.User = new GenericPrincipal(new GenericIdentity(..), roles);
    > >>
    > >> ---------------------------------------
    > >> Dominick Baier - DevelopMentor
    > >> [url]http://www.leastprivilege.com[/url]
    > >>> Hi
    > >>> I have created two pages, the login.aspx and the formA.aspx, and
    > >>> each
    > >>> of
    > >>> this has a corresponding *.cs files for code separation
    > >>> the scenario is, I seems to be able to login / authenticated because
    > >>> formA.aspx got loaded. But when I added the following lines
    > >>> Label1.Text = HttpContext.Current.User.Identity.Name;
    > >>> to the Page_Load event under FormA.cs, the control Label1 simply not
    > >>> showing anything!
    > >>> Do I need to do anything to get the "User.Identity.Name" set? (in
    > >>> config
    > >>> files and / or after successful login)?
    > >>> What is the problem here, please?
    > >>> TIA
    > >>> ____
    > >>> username and password collected by login.aspx is authenticated
    > >>> against
    > >>> the
    > >>> AD with LDAP using the following code
    > >>> //
    > >>> DirectoryEntry entry = new DirectoryEntry(strPath, uName,
    > >>> pwd);
    > >>> try
    > >>> {
    > >>> // Bind to the native object to force authentication to
    > >>> happen
    > >>> Object obj = entry.NativeObject;
    > >>> }
    > >>> catch (Exception ex)
    > >>> {
    > >>> throw new Exception("User authentication failed: " +
    > >>> ex.Message);
    > >>> }
    > >>> Server.Transfer("formA.aspx");
    > >>> _______
    > >>> formA.aspx contains a form for user to fill out some information.
    >
    >
    >

    Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139