我在一个Asp.net MVC .net 4.5 Web项目中,该项目连接到Identity Server 4服务器以进行登录和注销。登录就可以了。当我尝试注销时,Request.IsAuthenticated仍然为true。我可以刷新,它的行为就像我仍然登录,直到关闭浏览器。当我打开它时,它将转到Identity Server登录页面。知道为什么吗?
退出代码:
Request.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType);
Session.Clear();
Session.Abandon();
响应标题:
HTTP / 1.1 200确定
缓存控制:无缓存
语法:无缓存
内容类型:application / json; charset = utf-8
过期:-1
服务器:Kestrel
Set-Cookie:idsrv.session = .; expires =星期日,2017年9月17日20:50:52 GMT;路径= /;安全
Set-Cookie:idsrv =; expires =星期四,格林尼治标准时间1970年1月1日00:00:00;路径= /;安全
X-Powered-By:ASP.NET
日期:2018年9月17日星期一20:50:52 GMT
严格的运输安全性:max-age = 157680000
内容长度:601
请求标头:
获取/ XWAdmin /帐户/登录HTTP / 1.1 主机:localhost 连接:保持活动状态 不安全升级请求:1 用户代理:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 68.0.3440.106 Safari / 537.36 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng, / ; q = 0.8 接受编码:gzip,deflate,br 接受语言:en-US,en; q = 0.9 Cookie:rurl = / XWAdmin /; __RequestVerificationToken_L1hXQWRtaW41 = wElsOf5d9ti5DtEOmBmEuD9WqhyFAIeVxbIGEFJ9axRvlBQkl2szOHZF5K8wnLG6o8djmjOoI1lk4FavA8X2mHzg3L7xJ5F .AspNet.Cookies = urAb_USLLWmxzlB4lshB6K8-iKdwdzoGlDbverK0SmKKQjBHrBEwTYyP-8pkTvZeuAKqvw8bOInLGpm_1fhfcHjwTps8fXk4ej-xIhQcOpQhux0NqSqE7MUPPDnDwLUDlZVCTiQ5ORm0IhL3hR4Noil0j3pAlUkRAQhZAOMVLATevufvDvxc3ZdzYtQr9jVf-UzGTW1zUClOlmb1YOPEnPoSL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6FuCmOiLiQE1kIhWRTu_L585gIBXyZBR_AEQeqRTObWPVsEn5tdcg3-U2SAcmv3AJ9jPt4s2G19D4H9aKX83T07vQILw-UzVqL8hDYjV-7cGzXYpqNIsuzVyiGz2xU6vT7F6OuGbQjkuFKcKb2rd88CJNsNv8X19XwBghKcbBwIPxX9fkAeASApv1mqdIN873CAEbJpai2HrzMOILwSD6xleXTxobo64cS3ix4qhRgeCE4JfTzgIl8NiQ83S46JKkKTm2RrtZygc4T4kuN6cUI6gikwhcKos2mk9IKf52skT_6LJ-J9HvYXN2k7s8sCdgEbyNIrZMSfm2y7HjytPWguMQjcLYoxMZzYgwOTWbh7qK2uA87RP8w70ClSP56_bAWg_0MYlLx0JQp6bdaWuADwMTzhuH6SiVgiob6tKq09CtobrleLwjcWs97kSw0chDZhWoc8DBrE61NiUfiGrFJTl3GsZoWLEGQkeNxKwG-fmB4Z6zdjiu_lgtMIrLGnzemSBh92P7nnd7BCuA1axU-6_eg85Z7DH7Ek0ZGqCgG99z-4WVO; .ASPXAUTH = 1F501DAE995CDF04BEEF4B1C207DEDA77BD115F54948F6A749E69F2AAD45C0AC786761D82AA541B55233EFE708B626D2D3B90DE2AFD7606B20FD3E323FD3FA263E8414DB71F6B6CD58A06498E9AFD0D4F1841022964B71DFCDEFD8564B401649F2A798931A2AFCD3C4721AA7E45D9E87155DA6D8B3956C2975896663DD193B7CB004E11FE2739A71966E9B3E674DCD9BC54225F0A80765FC51D214CE3DD59816F7B1423A3992BA01339C9994A2B20A674F195FA14B77E52810EA513C26564F85F5880C8BFD1C6D5D6CE9316B5096B3E1F3FDE1D233A899F6D13A1F4D7D36CBEEEED3425672FCEDA3D44097A738638969B70954B5B6FDB7B690E6A08845C31BBF587D6F15BEAFFC70293B7FCA4DD5926FACA3409A7542B0117770D014A1267E0424C220F1708B71EB5B5C232855A74BF7B16D82C0F780BE8BE780C68D04A98A043012990F929F74417DE955853FE3258C35262FEDC1B37B247BC80A145C20B1F9FC697028B22F379B233254332D2585BE0C3486053495527E86279E0719CADEED6769FA81F4012BB56E4FD62E4918FAE0A1AA87C8C025DC4F215CB9ABAFE6F16FCF0EC3BAFF0168089BD82A0A39407159114B1A115F59723478DEB74EE78A84B28E67AE9E2D5D72836B46CE63F7E0D4CD1155D52A56616E7BB833F3309F9339734A5777C7013A48DF9B9EA962DBC706 45B247A59231345EA1B159B7093A315693C4468F4F25C2A69BD3871D17762FD9EEEEE0BFD2B8C0F425A2F07FB0CCB1845EA1C92273A1537CEB784009BA2793EE92
这是我为使其结合多个建议而起作用的方法:
string[] ss = Request.GetOwinContext().Authentication.GetAuthenticationTypes().Select(o => o.AuthenticationType).ToArray();
Request.GetOwinContext().Authentication.SignOut(
new AuthenticationProperties
{
RedirectUri = Online.Server.Busi.Auth.Authentication.GetSingleSignOnRedirectUrl()
},
ss);
try
{
Session.Clear();
Session.Abandon();
}
catch
{ }
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);