0

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

当它重定向到我的重定向uri时,我在那里检查了forif(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);
                                }
                            }
                        });
    } 
} 

我希望它可以随时适用于任何浏览器。

4

0 回答 0