简体   繁体   English

在具有Azure AD凭据的ASP .NET MVC中长时间不活动后,如何处理CryptographicException?

[英]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: 我试过的

  • handle this error with customErrors - doesn't seem to work 使用customErrors处理此错误-似乎不起作用
  • catching it in: 抓住它:

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上的联合身份验证

  • problem does not exist while I'm using debugger and local machine, only on production - does it depend on IIS config? 仅在生产环境中使用调试器和本地计算机时不存在问题-它取决于IIS配置吗?
  • may I change sessionTimeout of Azure AD cookies not to wait 20 minutes every time? 我可以更改Azure AD cookie的sessionTimeout使其每次都不等待20分钟吗?
  • should I use 'static' machine key - not generated every time by Azure AD? 我应该使用“静态”机器密钥-不是每次由AD生成的吗?

我终于做了一个解决方法:我没有处理这个令人讨厌的异常,而是只是通过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.

相关问题 ASP.NET MVC 5 中的 Azure AD 身份验证 - Azure AD authentication in ASP.NET MVC 5 使用Azure AD时处理Asp.Net MVC中的令牌超时 - Handle token timeout in Asp.Net MVC when using Azure AD ASP.NET MVC如何将应用程序从ASP.NET身份转换为Azure AD - ASP.NET MVC How to convert application from ASP.NET Identity to Azure AD 通过Azure AD ADAL的ASP.NET MVC用户身份验证 - ASP.NET MVC User Authentication through Azure AD ADAL Azure AD 与 ASP.NET 核心 MVC 中的标识 - Azure AD with Identity in ASP.NET Core MVC 无法使用 OIDC 将 ASP.NET MVC 连接到 Azure AD - Can't connect ASP.NET MVC to Azure AD with OIDC 使用Azure AD身份验证的ASP.NET MVC-如何允许用户管理组/角色分配? - ASP.NET MVC using Azure AD authentication — how to allow users to administer group/role assignments? 如何使用Azure AD和asp.net MVC保护控制器访问 - How to secure controller access using Azure AD and asp.net MVC 在针对 Azure AD 注销 ASP.NET Core MVC 应用程序时如何修复错误 404? - How to fix error 404 when logging out on an ASP.NET Core MVC app against Azure AD? Azure ASP.NET 核心 MVC WebApp 的 AD 身份验证 - 如何自定义应用程序的 Redirect_URI! 发送 - Azure AD Authentication for ASP.NET Core MVC WebApp - how to customize the Redirect_URI the APPLICATION! sends
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM