问题描述
每当我从应用程序注销时,我都会进入“默认”注销页面(我相信此控制器操作内置于 .net 核心)。注销后如何执行注销重定向到我的应用程序中的自定义页面?我看不到一种方法来指定这一点,这肯定是可能的吗? (它是在旧版本的 .net 中)。
我使用 azure 广告,我的应用程序托管在 azure 中。这是配置
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
// Handling SameSite cookie according to https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
options.HandleSameSiteCookieCompatibility();
});
// Sign-in users with the Microsoft identity platform
services.AddMicrosoftIdentityWebAppAuthentication(Configuration,"AzureAd");
我在 appsettings.json 中也有这些设置
"CallbackPath": "/signin-oidc","SignedOutCallbackPath ": "/signout-callback-oidc"
我也试过这个
new RewriteOptions().Add(
context => {
if (context.HttpContext.Request.Path == "/AzureAD/Account/SignedOut")
{ context.HttpContext.Response.Redirect("/Home/Index"); }
})
);
甚至尝试使用这两种方法添加我自己的 AccountController
[HttpGet]
public override SignOutResult SignOut()
{
var callbackUrl = Url.Action(nameof(SignedOut),"Account",values: null,protocol: Request.Scheme);
return SignOut(
new AuthenticationProperties { RedirectUri = callbackUrl },CookieAuthenticationDefaults.AuthenticationScheme,OpenIdConnectDefaults.AuthenticationScheme);
}
[HttpGet]
public IActionResult SignedOut()
{
if (User.Identity.IsAuthenticated)
{
// Redirect to home page if the user is authenticated.
return RedirectToAction(nameof(HomeController.Index),"Home");
}
return RedirectToAction(nameof(HomeController.Index),"Home");
}
没有任何效果,我总是重定向到“默认”注销页面。任何人都可以帮忙吗?提前致谢
解决方法
我设法解决了这个问题,我把我的 Rewite 代码改成了这个
app.UseRewriter(
new RewriteOptions().Add(
context => {
if (context.HttpContext.Request.Path == "/MicrosoftIdentity/Account/SignedOut")
{ context.HttpContext.Response.Redirect("/Home/SignedOut"); }
})
);
这是我必须修改的部分 来自
"/AzureAD/Account/SignedOut"
到
"/MicrosoftIdentity/Account/SignedOut"
现在可以了