qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

当ASP.NET Forms验证方式遭遇苹果IOS

一、问题出现
  我在用ASP.NET MVC4做微信开发的时候,用Forms验证方式做为authentication。
  一般都是在web.config加:
  <authentication mode="Forms" >
  <forms loginUrl="~/Account/Login" name="webcookies"  slidingExpiration="true" timeout="30" />
  </authentication>
  然后用户登录成功后就设置Cookies,代码如下:
public static void SetTicket(HttpResponseBase response, bool remeberMe, int version, string identity, string displayName)
{
FormsAuthentication.SetAuthCookie(identity, remeberMe);
string userData = displayName;
var authTicket = new FormsAuthenticationTicket(
version,
identity,
DateTime.Now,
DateTime.Now.AddDays(remeberMe ? 30 : 1),
remeberMe,
userData);
string encrytedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,
encrytedTicket);
response.Cookies.Add(authCookie);
}
  我这里用FormsAuthenticationTicket.Version存储用户角色ID。
  一开始还为自己的机智和精巧的设计洋洋得意,而且在安卓手机上运行完全没有问题。但是在IOS上,不管我Version设置成什么值,它的值始终都是2。
  根据msdn的解释:如果 FormsAuthenticationTicket 是使用不提供 version 参数的构造函数创建的,则 Version 属性返回 2;否则,Version 属性返回提供给FormsAuthenticationTicket 构造函数的值。
  地址:http://technet.microsoft.com/zh-cn/magazine/system.web.security.formsauthenticationticket.version(VS.110).aspx
  我明明已经使用了提供 version 参数的构造函数创建的,但是在IOS上就是不好使。
  找了很多资料都没有得到一个很好的解释,希望博客园的园们能帮我解释一下这个问题呀。
  后来看到微软的那个页面最下面:支持的平台:
  Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(不支持服务器核心角色), Windows Server 2008 R2(支持带 SP1 或更高版本的服务器核心角色;不支持 Itanium)
  我也就释怀了。
  不管怎么着,困扰我许久的问题终于找到问题所在了,谨以此文告诫后来者。

posted on 2014-08-11 14:57 顺其自然EVO 阅读(375) 评论(3)  编辑  收藏

评论

# re: 当ASP.NET Forms验证方式遭遇苹果IOS[未登录] 2015-02-10 12:00 长风

后来你是怎么解决的  回复  更多评论   

# re: 当ASP.NET Forms验证方式遭遇苹果IOS[未登录] 2015-02-10 12:01 长风

我也见到这个问题  回复  更多评论   

# re: 当ASP.NET Forms验证方式遭遇苹果IOS 2015-06-02 17:26 马栋

@长风
我现在也遇到了这个问题,用.net 做了一个wap站,login登录用到forms验证,结果除了IOS MAC OS,安卓各类桌面系统都没有问题  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2015年2月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜