Проверьте настройки IIS / аутентификации ...
disabled - Anonymous Authentication
enabled - ASP.NET Impersonation
enabled - Windows Authentication
Это необходимо для IIS для передачи учетных данных пользователя на ваш веб-портал. Затем вы можете передать эти учетные данные, используя следующий пример кода ...
public ActionResult HitCRM()
{
var uri = System.Configuration.ConfigurationManager.AppSettings["CRMURI"];
ClientCredentials credentials = new ClientCredentials();
var dinfo = ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(new Uri(uri));
var dsp = new DiscoveryServiceProxy(dinfo, credentials);
dsp.Authenticate();
var retrieveOrganizationsRequest = new RetrieveOrganizationsRequest();
var retrieveOrganizationsResponse = dsp.Execute(retrieveOrganizationsRequest) as RetrieveOrganizationsResponse;
if (retrieveOrganizationsResponse.Details.Count == 1)
{
var organizationDetail = retrieveOrganizationsResponse.Details[0];
Uri orgServiceUri = new Uri(organizationDetail.Endpoints[EndpointType.OrganizationService]);
IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(orgServiceUri);
var creds = new ClientCredentials();
IOrganizationService organizationService = new OrganizationServiceProxy(orgConfigInfo, creds);
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
var systemUser = organizationService.Retrieve("systemuser", userid, new ColumnSet(new string[] { "firstname", "lastname" }));
// Retrieve the version of Microsoft Dynamics CRM.
var versionRequest = new RetrieveVersionRequest();
var versionResponse = (RetrieveVersionResponse)organizationService.Execute(versionRequest);
ViewBag.FirstName = systemUser.GetAttributeValue<string>("firstname");
ViewBag.LastName = systemUser.GetAttributeValue<string>("lastname");
ViewBag.Version = versionResponse.Version;
}
return View();
}