2011-01-30 17 views
1

私はAsp.Net MVC 3アプリケーションで作業しているので、私のアプリケーションで​​を使用しました。セッションとフォーム認証の問題:Asp.Net MVC 3

問題は、システムにログインした後、ブラウザを閉じて(ログアウトせずに)ブラウザでページを開いたとき(/Admin/ProductList/と言う)、page is still being invokedI got focus in my controller tooです。 [それは本当に悪いです! :(]私が欲しいもの

は、私は、ブラウザを閉じて、任意のページに再び戻ってきたときに、それが必要logged in pageに行く、である。

をご理解の与えられたコードを確認してください。

public void SignIn(string userName, bool isCookiePersistent) 
     { 

      FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(14), 
       createPersistentCookie, string.Empty); 

      HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, isCookiePersistent); 
      if (authTicket.IsPersistent) 
      { 
       authCookie.Expires = authTicket.Expiration; 
      } 

      authCookie.Value = FormsAuthentication.Encrypt(authTicket); 
      HttpContext.Current.Response.Cookies.Add(authCookie); 
     } 

public void SignOut() 
     { 
      FormsAuthentication.SignOut(); 
     } 

のWeb.Configコード:

<authentication mode="Forms"> 
     <forms loginUrl="~/Admin/Login" timeout="2880" /> 
    </authentication> 

My page is getting in **Redirection Loop**: This is the main issue. 

アムI行方不明any other settings or global.asax event handling

私に何か解決策を教えてください。

ありがとうございます。ここで

答えて

3

authCookie.Expires = authTicket.Expiration; 

認証Cookieを永続的にするものだとあなたは、ブラウザを再起動すると、クッキーがまだそこにあるように、ブラウザがクライアントコンピュータ上に格納します。あなたが永続的なクッキーを望まない場合は、これを試すことができます:

public void SignIn(string userName) 
{ 
    var authTicket = new FormsAuthenticationTicket(
     1, userName, DateTime.Now, DateTime.Now.AddDays(14), false, string.Empty 
    ); 
    var authCookie = FormsAuthentication.GetAuthCookie(userName, false); 
    authCookie.Value = FormsAuthentication.Encrypt(authTicket); 
    HttpContext.Current.Response.Cookies.Add(authCookie); 
} 
+0

お返事ありがとう!しかし、これは動作していない、実際に私はブラウザを閉じて、再び任意のURLを参照してください、ページが空白として表示されます!何も起こっていません....それは空白のページとして開きます... – nunu

+0

@nunuは、あなたが '[Authorize]'属性で飾られた操作を試みていますか?これが、ユーザーが認証されていない場合にログイン画面にリダイレクトされる原因です。 –

+0

いいえ、[承認]属性を使用していません。実際に私がどのページに戻ってきても、何ページ分のリクエストがあっても、白いページを開いています... – nunu

関連する問題