Forms Auth を使用しているサイトがあります。クライアントは、ユーザーのサイト セッションが期限切れになることをまったく望んでいません。ログイン ページのコード ビハインドでは、次のコードが使用されます。
// user passed validation
FormsAuthentication.Initialize();
// grab the user's roles out of the database
String strRole = AssignRoles(UserName.Text);
// creates forms auth ticket with expiration date of 100 years from now and make it persistent
FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1,
UserName.Text, DateTime.Now,
DateTime.Now.AddYears(100), true, strRole,
FormsAuthentication.FormsCookiePath);
// create a cookie and throw the ticket in there, set expiration date to 100 years from now
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(fat)) { Expires = DateTime.Now.AddYears(100) };
// add the cookie to the response queue
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text, false));
web.config ファイルの認証セクションは次のようになります。
<authentication mode="Forms">
<forms name="APLOnlineCompliance" loginUrl="~/Login.aspx" defaultUrl="~/Course/CourseViewer.aspx" />
</authentication>
サイトにログインすると、Cookie が正しくブラウザに送信されて戻ってくることがわかります。
HttpFox 出力 http://cid-e79f8e4b07c3e30f.office.live.com/embedphoto.aspx/Public/SessionProblem.png
しかし、20 分ほど離れてからサイトに戻って何かをしようとすると、ログイン ウィンドウが再び表示されます。このソリューションは、当社のサーバーでしばらく機能していましたが、現在は機能しています。VS2008 で Cassini を実行しているローカルの開発ボックスでは問題は発生しません。
これを修正する方法についてのアイデアはありますか?