User.Identity.Name returns nothing / NULL

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

  1. Guest

    Guest Guest

    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

    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?

    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);
    // Bind to the native object to force authentication to happen
    Object obj = entry.NativeObject;
    catch (Exception ex)
    throw new Exception("User authentication failed: " +

    formA.aspx contains a form for user to fill out some information.
    Guest, May 9, 2005
    1. Advertisements

  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
    Dominick Baier [DevelopMentor], May 9, 2005
    1. Advertisements

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

    Guest Guest

    Hi Dominick
    I think this is the problem, and I found the following link under MS
    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 /
    Is there any other good example on Form authentication along with the
    required Global.asax file?

    Guest, May 9, 2005
  5. Hello dl,

    there is a sample on my blog which shows you how do this:

    btw - you can always get a context by calling:

    HttpContext context = HttpContext.Current;

    feel free to ask if you have any questions

    Dominick Baier - DevelopMentor
    Dominick Baier [DevelopMentor], May 9, 2005
  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 ?!


    Guest, May 10, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.