简体   繁体   English

我在使用C#向Dynamics 365普通用户进行身份验证时遇到错误

[英]I am getting error on authenticate to dynamics 365 normal user with c#

Hello experts, I am stuck at 'authentication to dynamics 365 with normal user'. 您好专家,我被困在“普通用户对Dynamics 365的身份验证”上。 I write a code in c# for authentication to dynamics 365. It works properly for the user who has admin of that organization but when I create a user into that org and sign up with the c# code it gives me 'Object reference not set to an instance of an object.' 我用C#写了一个代码,用于对Dynamics 365进行身份验证。该代码对于拥有该组织管理员的用户可以正常使用,但是当我在该组织中创建用户并使用c#代码进行注册时,它为我提供了“对象引用未设置为对象的实例。” error on 'IOrganization service'.Below is my c# code for authenticating the user. “ IOrganization服务”上的错误。下面是我的用于验证用户身份的C#代码。

public AuthenticateUser authenticateUserByFetchXML(string URL, string username, string password)
    {
        try
        {
            // model class
            AuthenticateUser user = new AuthenticateUser();
            EntityReference resultRef = new EntityReference();

            IOrganizationService service;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //put input into service
            CrmServiceClient GetCrmServiceClient = new CrmServiceClient(@"AuthType=Office365;Username='" + username + "'; Password='" + password + "';Url='" + URL + "'");

            //get organization web client by Iorganization service
            service = (IOrganizationService)GetCrmServiceClient.OrganizationWebProxyClient != null ? (IOrganizationService)GetCrmServiceClient.OrganizationWebProxyClient : (IOrganizationService)GetCrmServiceClient.OrganizationServiceProxy;

            //Get fetchXML for system user
              string fetchuser = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                          "<entity name='systemuser'>" +
                            "<attribute name='fullname' />" +
                            "<attribute name='businessunitid' />" +
                            "<attribute name='title' />" +
                            "<attribute name='address1_telephone1' />" +
                            "<attribute name='positionid' />" +
                            "<attribute name='systemuserid' />" +
                            "<order attribute='fullname' descending='false' />" +
                          "</entity>" +
                        "</fetch>";
            EntityCollection users = new EntityCollection();
            users = service.RetrieveMultiple(new FetchExpression(fetchuser));

            if (users.Entities.Count > 0)
            {

                Guid gId = users.Entities[0].Id;
                 user.Id = gId;              
                return user;
            }
            return user;

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

what can I write extra code for authenticate with normal user using this code. 我可以使用此代码编写额外的代码以进行普通用户身份验证。

When you create a user, it has no security roles and can't do anything (including logging in). 创建用户时,它没有安全角色,并且无法执行任何操作(包括登录)。 The error you get is what is seen in this scenario. 您收到的错误是在这种情况下看到的。

Make sure the new user has at least one security role. 确保新用户至少具有一个安全角色。

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

相关问题 如何在 Dynamics 365 C# 插件中查询用户的团队? - How do I query a user's teams in Dynamics 365 C# plugin? 对于C#中的用户控件,我收到的错误就像“类型&#39;上的构造函数&#39;system.string&#39;找不到”? - I am getting error like “constructor on type 'system.string' cannot found” for a User Control in C#? 使用 C# 对 Office 365 进行身份验证并获取用户信息并以表单形式显示 - Authenticate Office 365 and fetch user information and display in form using C# 客户端为 Dynamics 365 添加了新沙盒,尝试插入数据时出现 401 错误 - Client added new sandbox for Dynamics 365, and when trying to insert data I'm getting a 401 error "在我的 C# 代码中,我收到了这种类型的错误" - in my C# code i am getting this type of Error 为什么在C#类中出现此错误? - Why Am I getting this error in C# class? 为什么我在 C# 中使用 Dispose() 时出错 - Why I am getting error when using Dispose() in C# C# 我正在尝试使用自定义类创建一个 web 用户控件,但出现 Object 未设置为 Object 错误的实例 - C# I'm trying to create a web user control with custom classes, and I am getting a Object not set to an instance of an Object Error 通过Azure功能通过Dynamics 365进行身份验证 - Authenticate with Dynamics 365 from an Azure Function C# Memory 从 Dynamics 365 检索实体详细信息 - C# Out of Memory retrieving entity details from Dynamics 365
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM