Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查Microsoft Azure Active Directory中是否存在用户名_C#_Asp.net Mvc_Azure_Asp.net Mvc 5_Azure Active Directory - Fatal编程技术网

C# 检查Microsoft Azure Active Directory中是否存在用户名

C# 检查Microsoft Azure Active Directory中是否存在用户名,c#,asp.net-mvc,azure,asp.net-mvc-5,azure-active-directory,C#,Asp.net Mvc,Azure,Asp.net Mvc 5,Azure Active Directory,我正在使用Microsoft Azure Active Directory登录我的MVC 5应用程序。有人能告诉我如何检查Microsoft Azure Active Directory中是否已经存在用户名吗 执行此操作的一般方法是什么?您可以使用Graph API并查询所需的用户。有关Graph API的信息,请阅读: 公共查询页面()有一个给定userPrincipalName的用户查询。您应该使用此查询并检查它是否返回404(未找到) 基本上,您要查找的查询是:“其中您需要将contoso

我正在使用Microsoft Azure Active Directory登录我的MVC 5应用程序。有人能告诉我如何检查Microsoft Azure Active Directory中是否已经存在用户名吗


执行此操作的一般方法是什么?

您可以使用Graph API并查询所需的用户。有关Graph API的信息,请阅读:
公共查询页面()有一个给定userPrincipalName的用户查询。您应该使用此查询并检查它是否返回404(未找到)

基本上,您要查找的查询是:“其中您需要将contoso.com替换为您的域和admin@contoso.com使用要搜索的upn

你也应该看看这个。在本例中,您可能对如何使用Graph API感兴趣:

此示例MVC web应用程序演示如何使用Graph API查询Azure Active Directory。为了便于应用程序开发,它包括显示如何使用包含的图形库,并使用OpenID Connect授权用户访问其目录数据


另一种解决方案:

  public async Task<User> FindByAlias(string alias, GraphServiceClient graphClient)
        {
            List<QueryOption> queryOptions = new List<QueryOption>
            {
                new QueryOption("$filter", $@"mailNickname eq '{alias}'")
            };

            var userResult = await graphClient.Users.Request(queryOptions).GetAsync();
            if (userResult.Count != 1) throw new ApplicationException($"Unable to find a user with the alias {alias}");
            return userResult[0];
        }
公共异步任务FindByAlias(字符串别名,GraphServiceClient graphClient)
{
列表查询选项=新列表
{
新的查询选项(“$filter”,“$@”mailNickname eq'{alias}'”)
};
var userResult=await-graphClient.Users.Request(queryOptions.GetAsync();
如果(userResult.Count!=1)抛出新的ApplicationException($“找不到别名为{alias}的用户”);
返回userResult[0];
}

是否为WAAD
Windows Azure Active Directory身份验证
?如果是这样的话,你可能应该这么说,而不是假设每个人都熟悉这个不太常见的首字母缩略词。你也可以用@JohnKoerner标记它。也许他正在处理一个新的用户表单,需要确保用户名没有被使用。我已经编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。