[英]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.