闲置约40分钟后,SPA请求失败

尼古拉

为什么在闲置约40分钟后我的请求开始失败?

我建立了与https://github.com/Azure-Samples/active-directory-dotnet-webapp-groupclaims中相同的身份验证机制(我正在使用Asp.Net MVC4:

public partial class Startup
{
    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = ConfigHelper.ClientId,
                Authority = ConfigHelper.Authority,
                PostLogoutRedirectUri = ConfigHelper.PostLogoutRedirectUri,
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthorizationCodeReceived = async context =>
                    {
                        ClientCredential credential = new ClientCredential(ConfigHelper.ClientId, ConfigHelper.AppKey);
                        string userObjectId = context.AuthenticationTicket.Identity.FindFirst(Globals.ObjectIdClaimType).Value;
                        AuthenticationContext authContext = new AuthenticationContext(ConfigHelper.Authority, new TokenDbCache(userObjectId));
                        AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
                            context.Code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, ConfigHelper.GraphResourceId);
                    },

                    AuthenticationFailed = context =>
                    {
                        context.HandleResponse();
                        context.Response.Redirect("/Error/ShowError?signIn=true&errorMessage=" + context.Exception.Message);
                        return Task.FromResult(0);
                    }
                }
            });
    }
}

我正在使用angular2 SPA应用程序,并且在一段时间不活动之后,当应用程序尝试发送请求时,此请求失败(在chrome工具中,我看到API请求已重定向到身份验证服务器(azure aad),但服务器未正确处理它们并且我在客户端看到了身份验证服务器的响应。)

如果刷新页面,一切正常。

我已经禁用了IIS回收并设置了iddleTimout = 0。

在web.config中,我禁用了默认身份验证:

<authentication mode="None" />
<sessionState timeout="1440">
尼古拉

事实证明,如果OpenIdConnectAuthenticationOptions UseTokenLifetime将其设置为true,则cookie过期时间设置将被忽略。另外,我发现我正在使用默认情况下将此设置设置为true的库。此默认行为已更改,现在UseTokenLifetime默认情况下设置为false:https : //github.com/aspnet/Security/commit/966fa6672ff3c5bd75703c325512778722ff46a2#diff-c130fbf3a8ec2c0c32beaf27fcf04ea9

所以

 new OpenIdConnectAuthenticationOptions
                { UseTokenLifetime = false }

解决了我的问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在PHP中闲置15分钟后自动注销

来自分类Dev

Node.js:http请求在1分钟后超时

来自分类Dev

2分钟后线程什么也不做

来自分类Dev

1分钟后如何使用javascript刷新Repeater?

来自分类Dev

运行jQuery脚本发出Ajax请求2分钟后,出现错误net :: ERR_INSUFFICIENT_RESOURCES

来自分类Dev

用户会话在20分钟后关闭

来自分类Dev

PHP会话在40分钟后过期

来自分类Dev

5分钟后更新数据库

来自分类Dev

十分钟后svnsync超时

来自分类Dev

使用管道进行多处理-应用程序始终在约5分钟后停止

来自分类Dev

闲置5分钟后,Netty WebSocket客户端无法从服务器读取新帧

来自分类Dev

@reboot 1分钟后如何开始Cron作业?

来自分类Dev

启动后15分钟,Ubuntu非常慢

来自分类Dev

如果azure VM闲置了30分钟,我需要将其关闭

来自分类Dev

S3的Codedeploy总是在5分钟后失败

来自分类Dev

内置系统无法在关机时关闭电源,因此无法在关机后约10分钟内开机自检

来自分类Dev

如果闲置超过30分钟,如何关闭Linux?

来自分类Dev

Apache请求恰好挂了2分钟

来自分类Dev

在PHP中闲置15分钟后自动注销

来自分类Dev

5分钟后无声音

来自分类Dev

闲置5分钟后,i3屏幕变黑

来自分类Dev

首次收到GET-请求后30分钟如何发送推文?

来自分类Dev

30分钟后性能下降

来自分类Dev

使用RTL8821AE在约5分钟后Wifi掉线

来自分类Dev

约20分钟后服务器崩溃

来自分类Dev

三星显示器在约15分钟后自行更改分辨率

来自分类Dev

1分钟后截图

来自分类Dev

笔记本电脑使用超过40分钟后发出短促的蜂鸣声

来自分类Dev

15 分钟后 IIS 请求失败