SIT环境中的一段时间后,Azure AD身份验证失败

时间:2019-07-03 09:59:40

标签: asp.net-mvc azure azure-active-directory owin azure-ad-b2b

我已经在MVC应用程序中实现了AZure广告。它在本地环境中运行良好。 但是在SIT Environment上部署后,它可以正常工作1个小时。 在其他浏览器或隐身模式下开始失败后。 再次,当我重新启动应用程序时,它开始工作。

当它重定向到我的redirect-uri时,我在那里检查了(Request.IsAuthenticated)

,并且在隐身模式或其他不存储该应用程序cookie的浏览器中返回false。

命名空间Abcd {     公共局部类启动     {

    // Calling the keys values from Web.config file  
    private static string clientId = ConfigurationManager.AppSettings["ClientId"];
    private static string tenant = ConfigurationManager.AppSettings["Tenant"];
    private static string aadInstance = ConfigurationManager.AppSettings["Authority"];
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["RedirectUri"];

    // Concatenate aadInstance, tenant to form authority value       
    private string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, tenant);


    // ConfigureAuth method  
    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(

                        new OpenIdConnectAuthenticationOptions
                        {
                            ClientId = clientId,
                            Authority = authority,
                            RedirectUri = postLogoutRedirectUri,
                            PostLogoutRedirectUri = postLogoutRedirectUri,
                            Notifications = new OpenIdConnectAuthenticationNotifications
                            {
                                AuthenticationFailed = (context) =>
                                {
                                    context.HandleResponse();
                                    context.OwinContext.Response.Redirect("/Home/Index");
                                    return Task.FromResult(0);
                                }
                            }
                        });
    } 
} 

} 我希望它可以随时在任何浏览器上运行。

0 个答案:

没有答案