ASP.NETCore7与Blazor可以在NavigateToLogin中使用域提示吗?
创始人
2024-09-17 18:00:37
0

是的,可以在NavigateToLogin中使用域提示。以下是一个示例:

在Index.razor文件中:

@page "/"

@inject NavigationManager NavigationManager

@if (User.Identity.IsAuthenticated)
{
    

Hello, @User.Identity.Name!

} else {

Your application content here.

} @code { private async Task LogIn() { var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri); var domainHint = "example.com"; var authenticateResult = await AuthenticationStateProvider.GetAuthenticationStateAsync(); if (authenticateResult.User.Identity.IsAuthenticated) { NavigationManager.NavigateTo(returnUrl); } else { NavigationManager.NavigateTo($"https://login.microsoftonline.com/{domainHint}/oauth2/v2.0/authorize?client_id=YOUR_APP_ID&response_type=code&redirect_uri={WebUtility.UrlEncode(returnUrl)}&scope=User.Read openid&response_mode=query"); } } private async Task LogOut() { var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri); var domainHint = "example.com"; await SignOutManager.SignOutAsync(); NavigationManager.NavigateTo($"https://login.microsoftonline.com/{domainHint}/oauth2/logout?post_logout_redirect_uri={WebUtility.UrlEncode(returnUrl)}"); } }

在Startup.cs文件中,确保你的登录URL以https://login.microsoftonline.com/开头,因为这是NavigateToLogin使用的URL。

services.AddAuthentication(options =>
{
    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = "OpenIdConnect";
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect("OpenIdConnect", options =>
{
    options.Authority = "https://login.microsoftonline.com/common/v2.0";
    options.ClientId = "YOUR_APP_ID_HERE";
    options.ResponseType = "code";
    options.CallbackPath = "/signin-

相关内容

热门资讯

记者获悉!德州私人局怎么透视,... 记者获悉!德州私人局怎么透视,德普之星私人局透视,一直是真的有挂(有挂存在)1、下载好德普之星私人局...
避坑细节!pokemmo脚本辅... 避坑细节!pokemmo脚本辅助器下载,智星菠萝有挂吗,果然真的有挂(有挂秘笈)1、每一步都需要思考...
2026版方法!德普之星私人局... 2026版方法!德普之星私人局透视,德扑之心免费透视,切实确实有挂(有挂透视)1、让任何用户在无需德...
一分钟教会你!wepoker正... 一分钟教会你!wepoker正确养号方法,hhpoker是真的假的,竟然是真的有挂(新版有挂)1、下...
2026版方法!wepoker... 2026版方法!wepoker究竟有没有透视,德普辅助软件,都是真的是有挂(有挂规律)1、打开软件启...
教程辅助!wepoker怎么买... 教程辅助!wepoker怎么买辅助,wepokerh5破解,确实有挂(存在有挂)1、起透看视 辅助软...
近日!wepoker分析,智星... 近日!wepoker分析,智星德州有脚本吗,果然确实有挂(真是有挂)亲,关键说明,智星德州有脚本吗透...
分享实测!wepoker辅助器... 分享实测!wepoker辅助器软件下载,wepokerplus外挂,切实是有挂(有挂讲解)1、每一步...
出乎意料的是!hhpoker可... 出乎意料的是!hhpoker可以控制吗,德普之星透视辅助软件下载,确实确实有挂(有挂方式)德普之星透...
记者揭秘!wepoker破解器... 记者揭秘!wepoker破解器激活码,hhpoker真的有透视吗,竟然有挂(有挂功能)1. 选牌创建...