當(dāng)ASP.NET Forms驗(yàn)證方式遭遇蘋果IOS
一、問題出現(xiàn)
我在用ASP.NET MVC4做微信開發(fā)的時候,用Forms驗(yàn)證方式做為authentication。
一般都是在web.config加:
<authentication mode="Forms" >
<forms loginUrl="~/Account/Login" name="webcookies" slidingExpiration="true" timeout="30" />
</authentication>
然后用戶登錄成功后就設(shè)置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存儲用戶角色I(xiàn)D。
一開始還為自己的機(jī)智和精巧的設(shè)計洋洋得意,而且在安卓手機(jī)上運(yùn)行完全沒有問題。但是在IOS上,不管我Version設(shè)置成什么值,它的值始終都是2。
根據(jù)msdn的解釋:如果 FormsAuthenticationTicket 是使用不提供 version 參數(shù)的構(gòu)造函數(shù)創(chuàng)建的,則 Version 屬性返回 2;否則,Version 屬性返回提供給FormsAuthenticationTicket 構(gòu)造函數(shù)的值。
地址:http://technet.microsoft.com/zh-cn/magazine/system.web.security.formsauthenticationticket.version(VS.110).aspx
我明明已經(jīng)使用了提供 version 參數(shù)的構(gòu)造函數(shù)創(chuàng)建的,但是在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(不支持服務(wù)器核心角色), Windows Server 2008 R2(支持帶 SP1 或更高版本的服務(wù)器核心角色;不支持 Itanium)
我也就釋懷了。
不管怎么著,困擾我許久的問題終于找到問題所在了,謹(jǐn)以此文告誡后來者。