Httpcontext.current.User.Identity.Name is null RRS feed

  • Question

  • User-2142255709 posted

    Hello all,

             I'm using SQlmembership provider and login control in my application.

    The code behind is as below:
    protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e)
                bool authenticate;
                authenticate = ValidateUser(Login1.UserName, Login1.Password);
                if (authenticate)
                    if (Authorized("emprule"))
                        string s= HttpContext.Current.User.Identity.Name;
                    Response.Write("Login failed");
            public static bool ValidateUser(string Username,string Password)
                Boolean bauthenticated = false;
                bauthenticated = Membership.ValidateUser(Username,Password);
                if (!bauthenticated)
                    return false;
                IIdentity identity;
                identity = new GenericIdentity(Username, Membership.Provider.Name);
                // TODO: Get Roles
                string[] roles = Roles.GetRolesForUser(identity.Name);
                IPrincipal principal = new GenericPrincipal(identity, roles);
                // Place user's principal on the thread
                 Thread.CurrentPrincipal = principal;
                 HttpContext.Current.User = principal;
                 return bauthenticated;
            public static bool Authorized(string rule)
                bool authorized = false;
                // TODO: Check rule-base authorization
                // No parameter passed to GetAuthorizationProvider method as 
                // we'll set the defaultAuthorizationInstance in App.config.
                IAuthorizationProvider ruleProvider;
                ruleProvider = AuthorizationFactory.GetAuthorizationProvider();
                authorized = ruleProvider.Authorize(Thread.CurrentPrincipal, rule);
                return authorized;

    I'm getting the Httpcontext.current.user.identity.name value in this page,

    But when i redirect to other page and try to the get same

    I'm getting null value.

    Can anyone please help me with this.



    Tuesday, November 24, 2009 5:32 AM


All replies