Asp.net slidingExpiration无法使用手动创建的cookie

时间:2012-03-16 11:32:58

标签: asp.net

手动创建票证:

var ticket = new FormsAuthenticationTicket(
                1,
                username,
                DateTime.Now,
                DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
                false,
                "no,data",
                FormsAuthentication.FormsCookiePath
            );
var encryptedTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = FormsAuthentication.RequireSSL,
                Path = FormsAuthentication.FormsCookiePath,
                Domain = FormsAuthentication.CookieDomain
            };

HttpContext.Current.Response.AppendCookie(cookie);

Web.Config文件:

<forms loginUrl="~/LogOn"
       name="ticket"
       timeout="1"
       slidingExpiration="true"
       path="/" />

故障单创建发生在ASP.NET Web API中的方法中,客户端是与REST API通信的iPhone。

谢谢!

0 个答案:

没有答案