Note that there are some explanatory texts on larger screens.

plurals
  1. POIsAuthenticated works on browser - but not with Air client!
    primarykey
    data
    text
    <p>My login code, after authentication:</p> <pre><code>var authTicket = new FormsAuthenticationTicket( 1, userName, DateTime.Now, DateTime.Now.AddMinutes(20), // expiry false, roles, "/"); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); Response.Cookies.Add(cookie); </code></pre> <p>and, thanks to <a href="https://stackoverflow.com/questions/5314673/mvc-authentication-roles-not-working/5314736#5314736">Darin Dimitrov</a>, I have a custom Authorize attribute:</p> <pre><code>[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)] public class TJAuthorize : AuthorizeAttribute { public override void OnAuthorization(AuthorizationContext filterContext) { string cookieName = FormsAuthentication.FormsCookieName; if (!filterContext.HttpContext.User.Identity.IsAuthenticated || filterContext.HttpContext.Request.Cookies == null || filterContext.HttpContext.Request.Cookies[cookieName] == null) { HandleUnauthorizedRequest(filterContext); return; } var authCookie = filterContext.HttpContext.Request.Cookies[cookieName]; var authTicket = FormsAuthentication.Decrypt(authCookie.Value); string[] roles = authTicket.UserData.Split(','); var userIdentity = new GenericIdentity(authTicket.Name); var userPrincipal = new GenericPrincipal(userIdentity, roles); filterContext.HttpContext.User = userPrincipal; base.OnAuthorization(filterContext); } </code></pre> <p>This all works beautifully when I'm working in a browser session. But now I am working with a Flash/Adobe Air client, and the authentication attribute is causing a failure. By putting debug statements into the code, I can tell that:</p> <pre><code>filterContext.HttpContext.User.Identity.IsAuthenticated </code></pre> <p>is false - even after a successful login!</p> <p>Why should there be any difference between using a browser client and an Air client? And how do I fix this?</p> <p><strong>EDIT:</strong> Another clue: after putting in some more debug statements, I have found that the <code>filterContext.HttpContext.User.Identity</code> is not correctly set when making the call from Air - the <code>Name</code> property comes out blank! Session ID is correct, cookie ID is correct - but the <code>User.Identity</code> is not set. Any ideas why this might be happening?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload