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 閱讀(394) 評論(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,安卓各類桌面系統都沒有問題  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2014年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 石首市| 高青县| 庆阳市| 洛川县| 呼玛县| 志丹县| 马尔康县| 清镇市| 库尔勒市| 上蔡县| 邓州市| 手游| 三明市| 亚东县| 镇平县| 虞城县| 萨迦县| 长治市| 光泽县| 呼和浩特市| 夏邑县| 伊通| 达日县| 石景山区| 铁岭县| 兴宁市| 平邑县| 三亚市| 许昌县| 麻城市| 浦东新区| 泰宁县| 洛浦县| 繁峙县| 维西| 益阳市| 酉阳| 高尔夫| 都昌县| 鄂尔多斯市| 新邵县|