3 回答

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
用戶仍然可以瀏覽您的網(wǎng)站,因?yàn)樵谀鷵艽螂娫挄r(shí)不會(huì)清除Cookie,F(xiàn)ormsAuthentication.SignOut()并且每次新請(qǐng)求都會(huì)對(duì)其進(jìn)行身份驗(yàn)證。在MS文檔中說(shuō)cookie將被清除,但它們沒(méi)有,bug?與它完全相同Session.Abandon(),cookie仍然存在。
您應(yīng)該將代碼更改為:
FormsAuthentication.SignOut();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
SessionStateSection sessionStateSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");
HttpCookie cookie2 = new HttpCookie(sessionStateSection.CookieName, "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
FormsAuthentication.RedirectToLoginPage();
HttpCookie
在System.Web
命名空間中。MSDN參考。

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
聽(tīng)起來(lái)像你沒(méi)有正確設(shè)置你的web.config授權(quán)部分。請(qǐng)參閱下面的示例。
<authentication mode="Forms"> <forms name="MyCookie" loginUrl="Login.aspx" protection="All" timeout="90" slidingExpiration="true"></forms></authentication><authorization> <deny users="?" /></authorization>
- 3 回答
- 0 關(guān)注
- 1055 瀏覽
添加回答
舉報(bào)