2012-11-08 65 views
1

在我的應用程序已經使用Asp.Net窗體身份驗證,Asp.Net認證(獲得自動註銷)

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
        1, 
        adminResult.UserName, 
        DateTime.Now, 
        DateTime.Now.AddDays(2), 
        true, 
        "Administrator", 
        FormsAuthentication.FormsCookiePath 
        ); 
       string hash = FormsAuthentication.Encrypt(ticket); 
       HttpCookie coockie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); 
       if (ticket.IsPersistent) 
       { 
        coockie.Expires = ticket.Expiration; 
       } 
       Response.Cookies.Add(coockie); 
       if (Url.IsLocalUrl(returnUrl)) 
       { 
        return Redirect(returnUrl); 
       } 
       else 
       { 
        return RedirectToAction("Dashboard", "Cockpit"); 
       } 

但它會自動註銷越來越在10到15秒。

會是什麼解決方案?

感謝

+0

請分享你的web.config細節 – Yasser

+0

<形式名稱=「FXLWeb.ASPXAUTH 「loginUrl =」Home「protection =」All「path =」/「Cookieless =」UseCookies「slidingExpiration =」false「/> –

回答

0

可能是因爲垃圾收集清理和重新分配本機關鍵是你的應用程序。 Generate a machine key,並將其放置在web.config

<system.web> 
    <machineKey validationKey="###YOUR KEY HERE ###" 
       decryptionKey="## decrypt key here ##" 
       validation="SHA1" decryption="AES" /> 

的machineKey用於ViewState的加密和驗證和​​使用該密鑰簽署AUTH票,如果你不指定一個在web.config它是自動分配的,但如果你自己指定它集不會清楚它... HERE是翔實的文章,它可以幫助您更好地瞭解的重要性/ machineKey中

工作
+0

謝謝你,先生, 它的工作,機器的關鍵愚弄垃圾收集器。機器鑰匙如何完成工作,請回復。 –

+0

我編輯了答案以添加更多信息 – Rafay