Asp.Net Web Forms gives ticket error on iPads

2019-07-23 12:55发布

问题:

We have an existing ASP.Net Web Forms application that is installed on each client's own server. This has been used by them all for a while and never really had a problem, we now have some people who when logging on via an iPad get the error:

invalid value for encrypted ticket parameter

We have iPads here for testing and we don't get the error and despite getting them to ensure cookies are accepted in safari settings and even asking them to try Chrome on the iPad makes no difference. Not being able to replicate it makes it very difficult to diagnose so I'm hoping someone may have had this problem before.

It is using Forms authentication with a custom MembershipProvider.

回答1:

This happens if you pass an invalid string to System.Web.Security.FormsAuthentication.Decrypt. Most commonly its trying to pass in cookieName instead of cookieValue.

The following is the way to get the ASPXAUTH cookie value + info:

string authCookieValue = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value;
var cookieInfo = System.Web.Security.FormsAuthentication.Decrypt(authCookieValue);


回答2:

You have to check null for HttpCookie and also for it's value as given below .

HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
    if (authCookie != null)
    {
        //Extract the forms authentication cookie
        if (!string.IsNullOrEmpty(authCookie.Value))
        {
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            string email = authTicket.UserData;

            // and now process your code as per your condition

        }
    }