我的登录密码,验证后:IsAuthenticated适用于浏览器 - 但不适用于Air客户端!
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);
,并且由于Darin Dimitrov,我有一个自定义属性授权:
[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);
}
这一切精美的作品,当我在浏览器会话正在工作。但是现在我正在使用Flash/Adobe Air客户端,并且身份验证属性导致失败。通过将调试语句放入代码中,我可以发现:
filterContext.HttpContext.User.Identity.IsAuthenticated
即使在登录成功后也是false!
为什么使用浏览器客户端和Air客户端有什么区别?我该如何解决这个问题?
编辑:另一条线索:投入多一些调试语句后,我发现,filterContext.HttpContext.User.Identity
未正确设置使得从空气中呼叫时 - 在Name
财产出来空白!会话ID正确,Cookie ID正确 - 但未设置User.Identity
。任何想法,为什么这可能会发生?
令人惊叹 - 我在''中为''标记添加了'cookieless ='UseCookies'',现在它可以工作!你是天才,你! :) –
耶!感谢G-D! ......这是一个团队的努力 - 伟大的工作Shaul!谢谢@vnuk帮助我们朝着正确的方向思考! – davidkomer