ASP.netMVC.netframework4.8和ASP.netMVCCore6之间的共享用户身份不起作用。
创始人
2024-09-19 02:30:35
0

使用基于OpenID连接的身份验证来解决此问题。以下是示例代码:

首先,在ASP.net MVC .netframework 4.8中,您需要将身份验证设置为外部登录,以便用户可以使用外部身份验证提供程序进行身份验证。

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

app.UseOpenIdConnectAuthentication(
    new OpenIdConnectAuthenticationOptions
    {
        ClientId = "your_client_id",
        Authority = "https://your_authority.com/",
        RedirectUri = "http://your_redirect_uri.com",
        ResponseType = "id_token",
        Scope = "openid profile email",
        SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
    });

然后在ASP.net MVC Core 6中,您需要编写适当的代码来读取ASP.net MVC .netframework 4.8中设置的Cookie,并将其设置为当前用户身份。

var result = await HttpContext.AuthenticateAsync(
    CookieAuthenticationDefaults.AuthenticationScheme);

if (result?.Principal != null)
{
    var claims = result.Principal.Claims;
    var identity = new ClaimsIdentity(claims, "OpenIdConnect");
    HttpContext.SignInAsync(
        IdentityConstants.ApplicationScheme,
        result.Principal,
        new AuthenticationProperties { IsPersistent = false });
}

这样,用户身份将会在ASP.net MVC .netframework 4.8和ASP.net MVC Core 6之间共享。

相关内容

热门资讯

黑科技辅助!werplan辅助... 黑科技辅助!werplan辅助软件,德普之星透视辅助软件是真的吗,确实是有挂(有挂方略)德普之星透视...
做出回应!pokemmo免费脚... 做出回应!pokemmo免费脚本,德普辅助器怎么用,真是是真的有挂(有挂方略)暗藏猫腻,小编详细说明...
目前!wpk软件是正规的吗,智... 目前!wpk软件是正规的吗,智星菠萝透视,真是是有挂(有挂方略)1、下载好智星菠萝透视脚本下载之后点...
事发当天!hardrock作弊... 事发当天!hardrock作弊,德扑之星有辅助软件吗,竟然是有挂(有挂透视)1、德扑之星有辅助软件吗...
随着!wepoker可以开透视... 随着!wepoker可以开透视吗,智星德州插件怎么下载,好像真的是有挂(有挂教学)一、智星德州插件怎...
做出回应!如何下载wpk透视版... 做出回应!如何下载wpk透视版,德扑圈有透视吗,原来是真的有挂(存在有挂)1、起透看视 德扑圈有透视...
黑科技攻略!poker wor... 黑科技攻略!poker world辅助器,德普之星透视辅助软件激活码,原来是真的有挂(有挂详细)1、...
有消息称!wepoker透视脚... 有消息称!wepoker透视脚本免费,德普之星怎么开辅助,原来真的有挂(真的有挂)1、德普之星怎么开...
日前!wepoker底牌透视,... 日前!wepoker底牌透视,德扑之星私人局辅助免费,都是是真的有挂(的确有挂)1、完成德扑之星私人...
做出回应!wepoker怎么获... 做出回应!wepoker怎么获得好牌,德普之星透视辅助软件下载,好像是真的有挂(有挂头条)1、德普之...