System.Web.HttpContext.Current.User.Identity.IsAuthenticated fails sometimes

后端 未结 1 1915
生来不讨喜
生来不讨喜 2020-12-20 05:32

I have been having trouble with my production site (not my development sites). Every now and then both Firefox and Chrome fail to log users in (all users both on our client

相关标签:
1条回答
  • 2020-12-20 06:16

    If you use MembershipProvider, you do not need to create Form Authentication cookie by yourself.

    I answered one of your question, but after reading this, ignore that answer since you are using Membership Provider which will automatically create IPrincipal object for you.

    All you have to do is to use ASP.Net Login control.

    <asp:Login ID="Login" runat="server"></asp:Login>
    

    Note: applicationName should be same for both membership and roleManager. They are different in your web.config.

    How to View Authenticated User's Information

    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.IsAuthenticated)
        {
            var sb = new StringBuilder();
            var id = (FormsIdentity) User.Identity;
            var ticket = id.Ticket;
            sb.Append("Authenticated");
            sb.Append("<br/>CookiePath: " + ticket.CookiePath);
            sb.Append("<br/>Expiration: " + ticket.Expiration);
            sb.Append("<br/>Expired: " + ticket.Expired);
            sb.Append("<br/>IsPersistent: " + ticket.IsPersistent);
            sb.Append("<br/>IssueDate: " + ticket.IssueDate);
            sb.Append("<br/>Name: " + ticket.Name);
            sb.Append("<br/>UserData: " + ticket.UserData);
            sb.Append("<br/>Version: " + ticket.Version);
            Label1.Text = sb.ToString();
        }
        else
            Label1.Text = "Not Authenticated";
    }
    
    0 讨论(0)
提交回复
热议问题