當ASP.NET Forms驗證方式遭遇蘋果IOS

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   io   strong   

一、問題出現

我在用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)

我也就釋懷了。

不管怎麼著,困擾我許久的問題終於找到問題所在了,謹以此文告誡後來者。 

這個FormsAuthenticationTicket.Version 屬性是幹嘛的,有人知道不?

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.