gpt4 book ai didi

c# - 使用 Azure AD 时将用户重定向到自定义登录页面

转载 作者:太空狗 更新时间:2023-10-29 21:12:43 24 4
gpt4 key购买 nike

我使用以下代码示例将 Azure AD 登录插入到我的应用程序 (https://github.com/AzureADSamples/WebApp-OpenIDConnect-DotNet)。

我发现代码工作正常,但是如果用户尚未登录或他们的 session 已过期,我希望能够将用户重定向到自定义登录页面。然而,我正在努力让它发挥作用,并且想知道这是否真的可行?

是设计使用户始终被重定向到 Azure AD 的 Microsoft 登录页面而不是您自己的自定义页面,还是我遗漏了某个设置?

我修改了 FilterConfig.cs 中提供的代码以启用授权过滤器属性:

filters.Add(new AuthorizeAttribute());

我还在 web.config 中添加了以下内容,但没有效果:

<authorization>
<allow users="?" />
</authorization>

Startup.Auth.cs 文件中,我看不到任何可能对 app.UseOpenIdConnectAuthentication 进行的更改,以允许我尽可能地设置通用登录页面可能使用基于 cookie 的身份验证。

最佳答案

在重新检查代码后,我找到了问题的解决方案。

Startup.Auth.cs 中:

app.UseCookieAuthentication(new CookieAuthenticationOptions {
LoginPath = new PathString("/Account/Login")
});

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions {
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
AuthenticationMode = AuthenticationMode.Passive
});

包含 AuthenticationMode = AuthenticationMode.Passive 行似乎阻止 OpenIdConnectAuth 执行自动 302 重定向到 AAD 登录页面。

关于c# - 使用 Azure AD 时将用户重定向到自定义登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26517925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com