我們希望在MS CRM Dynamics中實施「記錄級安全性」。在用戶和案例實體,我們有一個OptionSet具有以下值,即Optionset有很多值的,下面只是簡單的數值:MS Dynamics中的記錄級安全性
- Category 1
- Category 2
我們要限制1類用戶僅查看第1類案件並限制第2類用戶僅查看第2類案件。
我到目前爲止做了什麼?
我在想這應該可以通過檢索插件,但是在我編寫我的代碼之後..我發現當我試圖打開一個案例記錄時,檢索插件觸發5次。它也不會拋出我的自定義錯誤。
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
tracer.Trace("context.Depth = " + context.Depth);
if (context.Depth > 1)
return;
tracer.Trace("context.Stage = " + context.Stage);
tracer.Trace("context.MessageName = " + context.MessageName);
EntityReference entityReference = (EntityReference)context.InputParameters["Target"];
tracer.Trace("entityReferencee = " + entityReference.LogicalName);
if (context.OutputParameters != null && context.OutputParameters.Contains("BusinessEntity"))
{
if (context.OutputParameters["BusinessEntity"] is Entity)
{
Entity entity = (Entity)context.OutputParameters["BusinessEntity"];
tracer.Trace("entity.LogicalName = " + entity.LogicalName);
context.OutputParameters["BusinessEntity"] = null;
throw new Exception("You can not view this record.");
}
else
{
tracer.Trace("BusinessEntity entity is not an entity.");
}
}
else
{
tracer.Trace("BusinessEntity entity is null");
}
}
詳細如下:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #CF526D62Detail:
-2147220970 System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #CF526D62
2015-09-21T12:33:00.6154994Z -2147220956 Unexpected exception from plug-in (Execute): RestrictUserAccess.Case: System.Exception: You can not view this record. 2015-09-21T12:33:00.6154994Z[RestrictUserAccess: RestrictUserAccess.Case] [c8860cb6-4260-e511-80ea-3863bb3600d8: RestrictUserAccess.Case: Retrieve of incident]
context.Depth = 1 context.Stage = 40 context.MessageName = Retrieve entityReferencee = incident entity.LogicalName = incident
您的檢索插件的代碼?你是如何註冊你的插件的? –
日誌文件('下載日誌文件')說什麼?另外,在一個側面說明,這是訪問團隊(應該是)的意圖,你有沒有考慮過這種方法? – Alex
您爲哪一步註冊了您的插件?你能分享堆棧跟蹤嗎? –