User.Identity.Name returns nothing / NULL

Discussion in 'ASP .Net Security' started by Guest, May 9, 2005.

  1. Guest

    Guest Guest

    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, May 9, 2005
    #1
    1. Advertising

  2. 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
    http://www.leastprivilege.com

    > 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], May 9, 2005
    #2
    1. Advertising

  3. 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
    http://www.leastprivilege.com

    > 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], May 9, 2005
    #3
  4. Guest

    Guest Guest

    Hi Dominick
    I think this is the problem, and I found the following link under MS
    http://msdn.microsoft.com/library/d...ve_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]" <>
    wrote in message news:...
    > 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
    > http://www.leastprivilege.com
    >
    > > 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, May 9, 2005
    #4
  5. Hello dl,

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

    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
    http://www.leastprivilege.com

    > Hi Dominick
    >
    > I think this is the problem, and I found the following link under MS
    >
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/s
    > 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]"
    > <> wrote in message
    > news:...
    >
    >> 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
    >> http://www.leastprivilege.com
    >>> 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], May 9, 2005
    #5
  6. Guest

    Guest Guest

    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]" <>
    wrote in message news:...
    > Hello dl,
    >
    > there is a sample on my blog which shows you how do this:
    >

    http://www.leastprivilege.com/PermaLink.aspx?guid=b0e51388-71d1-4a6f-98d0-bc8cfbec4c3a
    >
    > 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
    > http://www.leastprivilege.com
    >
    > > Hi Dominick
    > >
    > > I think this is the problem, and I found the following link under MS
    > >
    > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/s
    > > 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]"
    > > <> wrote in message
    > > news:...
    > >
    > >> 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
    > >> http://www.leastprivilege.com
    > >>> 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, May 10, 2005
    #6
    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. Giovanni Bassi
    Replies:
    0
    Views:
    623
    Giovanni Bassi
    Oct 20, 2003
  2. nalbayo
    Replies:
    2
    Views:
    5,472
    Bruce Barker
    Nov 11, 2005
  3. vizlab
    Replies:
    3
    Views:
    4,171
    Michael Bar-Sinai
    Oct 17, 2007
  4. JohnH.

    ASP.NET User.Identity.Name returns wrong value?

    JohnH., Mar 18, 2005, in forum: ASP .Net Security
    Replies:
    5
    Views:
    457
    JohnH.
    Mar 22, 2005
  5. Antonio O''Neal

    user.identity.name returns old AD user name

    Antonio O''Neal, Oct 31, 2008, in forum: ASP .Net Security
    Replies:
    5
    Views:
    2,037
    Antonio O''Neal
    Nov 3, 2008
Loading...

Share This Page