开发者

Form authentication is logging me out

开发者 https://www.devze.com 2023-04-12 06:19 出处:网络
I am using form authentication for by application and when the form times-out the application logs the user out to login page.

I am using form authentication for by application and when the form times-out the application logs the user out to login page.

But when I enter my credentials again, the application is not letting the user in. When I try it on another browser it works fine.I thought there might be problem with the cashing or cookies, so I cleared both cache and cookies from the browser. But this is still not working.

I am afraid that some thing might me wrong in my code.

Can some please check?

Many Thanks

protected void ManageRoles(string userid, string role)
    {
        FormsAuthentication.Initialize();

        FormsAuthenticationTicket Authticket = new FormsAuthenticationTicket(1, userid, DateTime.Now, DateTime.Now.AddMinutes(180), true, role, FormsAuthentication.FormsCookieName);
        string hash = FormsAuthentication.Encrypt(Authticket);
        HttpCookie Authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

        if (Authticket.IsPersistent)
        {
            Authcookie.Expires = Authticket.Expiration;
            Response.Cookies.Add(Authcookie);
        }               

    }

Global.asax

protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (HttpContext.Current.User != null)
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (HttpContext.Current.User.Identity is FormsIdentity)
                    {
                        FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
                        FormsAuthenticationTicket Authticket = id.Ticket;
                        string userData = Authticket.UserData;
                        string[] roles = userData.Split(',');
                        HttpContext.Current.User开发者_StackOverflow = new GenericPrincipal(id, roles);
                    }
                }
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号