我正在研究使用天蓝色广告的基于角色的授权。我大部分都了解如何在项目清单中创建和分配角色。我想知道的是,如果用户无权查看特定的页面和方法,该如何将其重定向到自定义的“未授权”页面。现在,当用户未经授权时,所有发生的事情就是将他们重定向到Microsoft登录屏幕,并说“我们无法登录。请重试。”
我在项目清单中尝试了不同的选项,但没有获得任何成功。
如果未授权用户,我要将他们重定向到自定义“未授权”页面。
答案 0 :(得分:0)
此问题的解决方案是使用AuthenticationMode.Passive,这样它就不会重定向到AAD登录页面
您必须在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登录页面的操作。
希望有帮助。