Banging meinen Kopf gegen eine Mauer wieder. Ich versuche, meine ASP.NET Web Forms-Webanwendung abzumelden, aber sie verweigert dies. Ich verwende die Formularauthentifizierung. Das Problem scheint zu sein, dass der Browser (ALLE, die ich ausprobiert habe) einen Cache der Seiten nach der Anmeldung beibehält, aber diesen Cache beim Abmelden nicht löscht.asp.net nicht Benutzer abmelden
Wenn ich auf der Hauptseite auf den Logout-Link klicke, übertrage ich mich erfolgreich auf die Anmeldeseite, aber ich kann einfach die URL der Seite eingeben oder auf den Browser drücken und die Seite erneut laden, ohne sich einloggen zu müssen .
Ich habe die letzten paar Stunden damit verbracht, StackOverflow und anderswo nach einer Lösung zu durchsuchen, aber bisher hat noch nichts funktioniert.
Meine Wurzel web.config hat dies:
<authentication mode ="Forms">
<forms loginUrl="~/Account/Login" name=".ASPXFORMSAUTH" defaultUrl="~/Default.aspx"></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
Dies ist die web.config in meinem Konto Ordner.
<configuration>
<location path="Manage.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
Dies ist mein Code zum Abmelden. Wie Sie sehen können, habe ich implementiert alles Ich habe online gefunden. Dies ist in der CS-Datei meiner Masterseite.
public void Logout_Click(object sender, EventArgs e)
{
ClearSession();
// Clear authentication cookie
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie.HttpOnly = true;
cookie.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie);
// Clear session cookie
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();
}
protected void ClearSession()
{
FormsAuthentication.SignOut();
Session.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ExpiresAbsolute = DateTime.UtcNow.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-Cache";
}
In meinem Page_Init (wieder Masterseite cs-Datei), ich habe dies:
protected void Page_Init(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");
// The code below helps to protect against XSRF attacks
var requestCookie = Request.Cookies[AntiXsrfTokenKey];
Guid requestCookieGuidValue;
if (requestCookie != null && Guid.TryParse(requestCookie.Value, out requestCookieGuidValue))
{
// Use the Anti-XSRF token from the cookie
_antiXsrfTokenValue = requestCookie.Value;
Page.ViewStateUserKey = _antiXsrfTokenValue;
}
else
{
// Generate a new Anti-XSRF token and save to the cookie
_antiXsrfTokenValue = Guid.NewGuid().ToString("N");
Page.ViewStateUserKey = _antiXsrfTokenValue;
var responseCookie = new HttpCookie(AntiXsrfTokenKey)
{
HttpOnly = true,
Value = _antiXsrfTokenValue
};
if (FormsAuthentication.RequireSSL && Request.IsSecureConnection)
{
responseCookie.Secure = true;
}
Response.Cookies.Set(responseCookie);
}
Page.PreLoad += master_Page_PreLoad;
}
Und schließlich in meinem Master-Seitenkopf, ich habe diese Meta-Tags.
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="cache-control" content="proxy-revalidate" />