Я реализовал AZure Ad в приложении MVC.Он отлично работает в локальной среде.но после развертывания в среде SIT он работает нормально 1 час.после сбоя в другом браузере или режиме инкогнито.Снова, когда я перезапускаю приложение, оно начинает работать.
Когда оно перенаправляется на мой redirect-uri, я проверял там forif (Request.IsAuthenticated)
, и он возвращает false в режиме инкогнито или в другом браузере, которыйне сохраняет файлы cookie для этого приложения.
пространство имен Abcd {открытый частичный класс Startup {
// 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);
}
}
});
}
}
}, я думаю, он должен работать для любого браузера в любое время.