简体   繁体   English

如果项目使用 Azure AD,当前用户 Id 是否可以在 ASP.NET Core 5 MVC controller 中访问?

[英]Is the current user Id accessible in an ASP.NET Core 5 MVC controller if the project uses Azure AD?

My site is using Azure AD for authentication I see that User.Identity.Name is available and I was wondering if the Guid uid is available in a similar fashion?我的站点使用 Azure AD 进行身份验证我看到User.Identity.Name可用,我想知道 Guid uid是否以类似的方式可用?

Thanks谢谢

One of the workaround could able to get the current user id from ASP.NET core MVC application.解决方法之一可以从 ASP.NET 核心 MVC 应用程序获取当前用户 ID。

We need to use the below:我们需要使用以下内容:

using Microsoft.AspNet.Identity;

Instead of using User.Identity.Name use this cmd User.Identity.GetUserId();而不是使用User.Identity.Name使用这个cmd User.Identity.GetUserId();

For more information please refer this SO THREAD有关更多信息,请参阅此SO 线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法使用 Azure AD 令牌对 ASP.NET Core MVC controller 操作进行身份验证? - Is there a way to authenticate an ASP.NET Core MVC controller action using an Azure AD token? 在asp.net mvc中授权Azure AD组 - Authorize for Azure AD groups in asp.net mvc 无法使用 OIDC 将 ASP.NET MVC 连接到 Azure AD - Can't connect ASP.NET MVC to Azure AD with OIDC 在 ASP.NET Core MVC 中从 Azure blob 容器提供 static 个文件 - Serve static files from Azure blob container in ASP.NET Core MVC 将 blob 从一个 Azure 容器复制到另一个使用 ASP.NET Core 6.0 MVC 和 C# - Copy blobs from one Azure container to another using ASP.NET Core 6.0 MVC with C# 使用Azure 2020 as Git时如何设置asp.net core中每个项目的权限 - how to set permission on each project in asp.net core when use Azure 2020 as Git .NET 5 ASP.NET 核心应用程序未在 Azure 中启动 - .NET 5 ASP.NET Core App not starting in Azure 如何使用 Azure Active Directory 在 ASP.NET Core 应用程序中获取经过身份验证的用户的名称 - How to get Name of Authenticated user in ASP.NET Core application using Azure Active Directory Asp.net Web Forms(非 MVC)azure 活动目录身份验证 - Asp.net Web Forms (NOT MVC) azure active directory authentication ASP.net 核心 docker https on Azure 应用服务容器 - ASP.net core docker https on Azure App Service Containers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM