もう一度レンガの壁に頭を向けます。私はASP.NET WebフォームWebアプリケーションをログアウトさせようとしていますが、これを拒否しています。私はフォーム認証を使用しています。問題は、ブラウザ(私が試したすべてのもの)がログイン後にそのページのキャッシュを維持しているが、ログアウト時にそのキャッシュをクリアしていないことにあるようだ。asp.netはログアウトしていません
メインページのログアウトリンクをクリックすると、私はログインページに正常に転送されますが、ページのURLを入力するかブラウザを押すだけで、ログインする必要なしにページが再びロードされます
私は過去数時間、StackOverflowやその他のソリューションを解決するために何時間も費やしてきましたが、今のところ何も機能していません。
マイルートweb.configファイルには、これを持っている:
<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"/>
これは私のアカウントフォルダ内のweb.configファイルです。
<configuration>
<location path="Manage.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
これはログアウトするためのコードです。ご覧のとおり、私はすべてを実装しました私はオンラインで見つけました。これは私のマスターページのcsファイルにあります。私のPage_Init(再び、マスターページのCSファイル)で
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";
}
、私はこれがあります。
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;
}
をそして最後に、私のマスターページのヘッダーに、私はこれらのメタタグを持っています。通常そうであるように
<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" />