HttpContext.Current.User.Identity.Name

Discussion in 'ASP .Net' started by Abraham Andres Luna, Oct 11, 2006.

  1. hello everyone,

    does anyone know why i can't access the
    HttpContext.Current.User.Identity.Name property in a .cs file?
    this is the index.aspx page:

    <%@ Page Language="C#" %>
    <script runat="server">
    void Page_Load(Object Sender, EventArgs E)
    {
    FormsAuthentication.SetAuthCookie("abe", false);
    lblError.Text = IS.Data.GetUSRNA();
    }
    </script>
    <html>
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form runat="server">
    <asp:Label ID="lblError" runat="server" />
    </form>
    </body>
    </html>

    and this is the .cs file located in the app_code directory:

    using System;
    using System.Web;
    namespace IS
    {
    public class Data
    {
    public static string GetUSRNA()
    {
    return HttpContext.Current.User.Identity.Name;
    }
    }
    }

    it doesn't make sense why i wouldn't be able to retreive the user name this
    way. maybe i'm missing something.

    thank you for your help
    Abraham Andres Luna, Oct 11, 2006
    #1
    1. Advertising

  2. i did some searching and read that even if i called
    FormsAuthentication.SetAuthCookie("abe", false) to set the user, the
    User.Identity.Name property will not be available until the next request. is
    there any way to force that property to be populated. otherwise, i'm going
    to have to call the setauthcookie, then redirect the page to access the
    user.identity.name property.

    thank you for your help

    "Abraham Andres Luna" <> wrote in message
    news:ee%...
    | hello everyone,
    |
    | does anyone know why i can't access the
    | HttpContext.Current.User.Identity.Name property in a .cs file?
    | this is the index.aspx page:
    |
    | <%@ Page Language="C#" %>
    | <script runat="server">
    | void Page_Load(Object Sender, EventArgs E)
    | {
    | FormsAuthentication.SetAuthCookie("abe", false);
    | lblError.Text = IS.Data.GetUSRNA();
    | }
    | </script>
    | <html>
    | <head runat="server">
    | <title>Untitled Page</title>
    | </head>
    | <body>
    | <form runat="server">
    | <asp:Label ID="lblError" runat="server" />
    | </form>
    | </body>
    | </html>
    |
    | and this is the .cs file located in the app_code directory:
    |
    | using System;
    | using System.Web;
    | namespace IS
    | {
    | public class Data
    | {
    | public static string GetUSRNA()
    | {
    | return HttpContext.Current.User.Identity.Name;
    | }
    | }
    | }
    |
    | it doesn't make sense why i wouldn't be able to retreive the user name
    this
    | way. maybe i'm missing something.
    |
    | thank you for your help
    |
    |
    Abraham Andres Luna, Oct 11, 2006
    #2
    1. Advertising

  3. >the User.Identity.Name property will not be available until the next
    >request


    Hmm, i use a custom method and i set the identity right after
    authentication, that might help you as well.
    This is similar (ticket)code as on each request on global.asax.





    "Abraham Andres Luna" <> schreef in bericht
    news:%...
    >i did some searching and read that even if i called
    > FormsAuthentication.SetAuthCookie("abe", false) to set the user, the
    > User.Identity.Name property will not be available until the next request.
    > is
    > there any way to force that property to be populated. otherwise, i'm going
    > to have to call the setauthcookie, then redirect the page to access the
    > user.identity.name property.
    >
    > thank you for your help
    >
    > "Abraham Andres Luna" <> wrote in message
    > news:ee%...
    > | hello everyone,
    > |
    > | does anyone know why i can't access the
    > | HttpContext.Current.User.Identity.Name property in a .cs file?
    > | this is the index.aspx page:
    > |
    > | <%@ Page Language="C#" %>
    > | <script runat="server">
    > | void Page_Load(Object Sender, EventArgs E)
    > | {
    > | FormsAuthentication.SetAuthCookie("abe", false);
    > | lblError.Text = IS.Data.GetUSRNA();
    > | }
    > | </script>
    > | <html>
    > | <head runat="server">
    > | <title>Untitled Page</title>
    > | </head>
    > | <body>
    > | <form runat="server">
    > | <asp:Label ID="lblError" runat="server" />
    > | </form>
    > | </body>
    > | </html>
    > |
    > | and this is the .cs file located in the app_code directory:
    > |
    > | using System;
    > | using System.Web;
    > | namespace IS
    > | {
    > | public class Data
    > | {
    > | public static string GetUSRNA()
    > | {
    > | return HttpContext.Current.User.Identity.Name;
    > | }
    > | }
    > | }
    > |
    > | it doesn't make sense why i wouldn't be able to retreive the user name
    > this
    > | way. maybe i'm missing something.
    > |
    > | thank you for your help
    > |
    > |
    >
    >
    Edwin Knoppert, Oct 12, 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. Giovanni Bassi
    Replies:
    0
    Views:
    626
    Giovanni Bassi
    Oct 20, 2003
  2. Dan Bart
    Replies:
    4
    Views:
    27,766
    Andrea D'Onofrio [MSFT]
    Dec 18, 2003
  3. Replies:
    10
    Views:
    3,468
    Kiran_S_Rao
    Dec 8, 2004
  4. =?Utf-8?B?dnZlbms=?=

    Help with HttpContext.Current.User.Identity.Name

    =?Utf-8?B?dnZlbms=?=, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    623
    Brock Allen
    Sep 29, 2005
  5. nalbayo
    Replies:
    2
    Views:
    5,476
    Bruce Barker
    Nov 11, 2005
Loading...

Share This Page