[英]How to handle CryptographicException after long inactivity in ASP .NET MVC with Azure AD credentials?
I'm using Azure Active Directory application which contains user data and credentials. 我正在使用包含用户数据和凭据的Azure Active Directory应用程序。 I access ASP .NET MVC 5 application with this credentials using Microsoft.Azure.ActiveDirectory.GraphClient library.
我使用Microsoft.Azure.ActiveDirectory.GraphClient库使用此凭据访问ASP .NET MVC 5应用程序。 After long inactivity, about 20 minutes, and clicking some link I got plain Server Runtime Error and cannot refresh page and login again.
长时间不活动后,大约20分钟,然后单击一些链接,我收到了“服务器运行时错误”,无法刷新页面并再次登录。 Only clearing cookies works.
仅清除cookie有效。
What I tried: 我试过的
protected void Application_Error(object sender, EventArgs e) { var error = Server.GetLastError(); var cryptoEx = error as CryptographicException; if (cryptoEx != null) { FederatedAuthentication.WSFederationAuthenticationModule.SignOut(); Server.ClearError(); HttpContext.Current.Response.Redirect("~/"); } }
as described here: Federated Authentication on Azure 如此处所述: Azure上的联合身份验证
我终于做了一个解决方法:我没有处理这个令人讨厌的异常,而是只是通过JavaScript调度的请求来保持会话,这些请求正在调用控制器并设置了一些Session["Value"]
I also handled this by making sure my pages refresh every 30 minutes. 我还通过确保页面每30分钟刷新一次来处理此问题。
This can be done in HTML by adding the meta tag 可以通过添加meta标签在HTML中完成
<meta http-equiv="refresh" content="1800">
It can also be done via Javascript 也可以通过Javascript完成
setInterval(function() {
window.location.reload();
}, 180000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.