首页 > 解决方案 > 将用户属性设置为 null 或 string.empty

问题描述

我正在尝试通过在 C# 应用程序中使用 Microsoft.Graph NuGet 包将 Azure AD 用户的值设置为 null 或 string.Empty。

那是我的代码:

public async Task<User> UpdateMobilePhone(string userId, string mobilePhone)
    {
        User user = new User();
        user.MobilePhone = mobilePhone;

        return await graphServiceClient.Users[userId]
            .Request()
            .UpdateAsync(user);
    }

如果将“mobilePhone”的值设置为 string.Empty,则会收到错误消息:Microsoft.Graph.ServiceException:“代码:Request_BadRequest 消息:为资源“用户”的属性“mobilePhone”指定的值无效。

如果我将“mobilePhone”的值设置为空,它什么也不会发生,因为空用户的默认值为空,所以他认为,什么都没有改变。

那么有人知道我可以如何解决我的问题吗?

谢谢转发

标签: c#nugetmicrosoft-graph-api

解决方案


推荐阅读