Integrating Dynamics CMS with Sharepoint ASCX SecurityException Issue
- by Gavin
Hi,
I've an ASCX control (WebParts aren't used in this solution) which interrogates CMS 4's data via the API provided by Microsoft.Crm.Sdk and Microsoft.Crm.SdkTypeProxy.
The solution works until it's deployed to Sharepoint.
Initially I received the following error:
[SecurityException: That assembly does not allow partially trusted callers.]
MyApp.SharePoint.Web.Applications.MyAppUtilities.RefreshUserFromCrm(String login) +0
MyApp.SharePoint.Web.Applications.MyApp_LoginForm.btnLogin_Click(Object sender, EventArgs e) +30
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
Then I tried wrapping the calling code in the ASCX with SPSecurity.RunWithElevatedPrivileges:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// FBA user may not exist yet or require refreshing
MyAppUtilities.RefreshUserFromCrm(txtUser.Text);
});
But this resulted in the following error:
[SecurityException: Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.]
MyApp.SharePoint.Web.Applications.MyApp_LoginForm.btnLogin_Click(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
When I elevate the trust level in the Sharepoint site to full everything works fine, however I need to come up with a solution that uses minimal trust (or a customised minimal trust). I'm also trying to stay clear of adding anything to the GAC. Any ideas?
I assume the issue is occuring when trying to call functionality from Microsoft.Crm.*
Thanks in advance for any help anyone can provide.
Cheers,
Gavin