簡體   English   中英

Dynamics365 CRM - 無法登錄到 Dynamics CRM

[英]Dynamics365 CRM - Unable to login to Dynamics CRM

過去 5 個月我一直在從事一個項目 - 集成我們的一個舊系統以使用 Dynamics365 CRM 為我們的營銷和銷售部門存儲和記錄潛在客戶。

一切都在多種環境中正常運行 - 我們有一個 DEV、Sandbox 以及 TEST 和我的本地機器。 除了托管在完全不同城市的 UAT 服務器之外,它可以在任何地方工作,而不是我們工作的建築物中的其他服務器。

我們已確保使用 TSL 1.2,並且應用程序在代碼中強制執行此操作。 比較所有機器上的 .NET 功能,它們完全相同,密碼和配置文件幾乎相同,差異很小,例如我們數據庫的連接字符串。

我們在所有環境中連接到同一個 CRM 實例。

該項目已使用 .NET 4.6.1 編譯

Microsoft.CrmSdk.CoreAssemblies - 9.0.2.4

Microsoft.CrmSdk.XrmTooling.CoreAssembly - 9.0.2.7

Microsoft.IdentityModel.Clients.ActiveDirectory - 2.22.302111727

我們的 Azure(我們使用 AD 通過 C# 登錄 CRM)沒有白名單。

據我們所知,Dynamics 沒有白名單。

沒有防火牆規則阻止 443 端口上的任何傳出連接,因此一切都類似於其他環境,但我們收到“無法登錄 Dynamics CRM ”錯誤消息。

這是我們用來連接到 CRM 的代碼。

string Thumbprint = ConfigurationManager.AppSettings["CertThumbprint"];
string adInstance = ConfigurationManager.AppSettings["ADInstance"];
string adTenant = ConfigurationManager.AppSettings["Tenant"];
string Url = ConfigurationManager.AppSettings["Application"];
string AppId = ConfigurationManager.AppSettings["ClientId"];

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);

certStore.Open(OpenFlags.ReadOnly);


X509Certificate2Collection CertificateCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, Thumbprint, false);

if (CertificateCollection.Count == 0) 
      throw new Exception("Error: Could not find the right certificate.");


X509Certificate2 AzureCertificate = CertificateCollection[0];


CrmServiceClient.AuthOverrideHook = new AuthHook(adInstance, adTenant, Url, AppId, AzureCertificate);

var crmSvc = new CrmServiceClient(new Uri(Url), true);

if (crmSvc == null || !crmSvc.IsReady) throw new Exception(crmSvc == null ? "CrmServiceClient Failure." : crmSvc.LastCrmException.ToString());

this.service = (IOrganizationService)crmSvc.OrganizationWebProxyClient ?? crmSvc.OrganizationServiceProxy;

此行專門返回錯誤並設置為空...

var crmSvc = new CrmServiceClient(new Uri(Url), true);

值得一提的是,UAT 與其他的唯一區別在於,與其他運行 .NET 4.7.2 的 UAT 相比,UAT 運行在 .NET 4.7.1 上。

如果有人遇到這個,將不勝感激或任何想法它可能是什么。


編輯:我剛剛嘗試使用 Office365 進行身份驗證的后備方法無濟於事。 同樣的錯誤......這種方法適用於所有其他環境。

使用的代碼是:

ClientCredentials clientCredentials = new ClientCredentials();

if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["crm_user"]) && 
    !string.IsNullOrEmpty(ConfigurationManager.AppSettings["crm_password"]))
{
    clientCredentials.UserName.UserName = ConfigurationManager.AppSettings["crm_user"];
    clientCredentials.UserName.Password = ConfigurationManager.AppSettings["crm_password"];

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

    this.service = (IOrganizationService)new OrganizationServiceProxy(new Uri(ConfigurationManager.AppSettings["crm_org_url"]),
                                        null, clientCredentials, null);

    if (this.service == null)
    {
        Exception e = new Exception("CRM: Could not login to organization service proxy.");

        throw e;
    }
}
else
{
    throw new Exception("CRM: Could not connect using a fallback method. The web configuration doesn't contain crm_user or crm_password keys.");
}

首先,感謝所有試圖提供幫助的人。

這個(3 天)問題的解決方案是我安裝在本地機器上的私鑰沒有 Web App 讀取它的正確權限。

我成功找到了密鑰,但代碼無法讀取它。

為了解決這個問題,我去了 MMC,將證書添加到我的視圖中,然后在個人文件夾中我有我的證書,右鍵單擊需要的那個,所有任務 > 管理私鑰並確保您的應用程序池在組或用戶中名稱部分。

值得添加的是,我還在我的應用程序池 (App Pools\\DefautApplicationPool) 旁邊添加了 IIS_IUSRS 組。

這神奇地解決了UAT問題。 CRM SDK 可以改進為...更直觀。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM