CRM2011/2016 – Timeout problem when open Sharepoint documents from CRM

Today I had a big problem with our new customer: When they tried to open a document from CRM, they had an error:

a

After check a little bit, I found a timeout error on sharepoint.  The problem was the Cookie life time configuration:

[..]When using FBA or a trusted provider, SharePoint will set a cookie on the client called FedAuth. I’ll not go into the details of what’s inside the FedAuth cookie. Of course, the FedAuth cookie will have by default a certain lifetime. Session cookies can be configured too making the cookie invalid after the closing the browser and then bypassing the value in this settings.

The default value is 5 days.[..] (Microsoft text)

cp1

To resolve the problem I found this script:

$sts = Get-SPSecurityTokenServiceConfig
$sts.CookieLifetime = New-TimeSpan -Hours 7
$sts.Update()

At the end I restart IIS and all is run in right way.

Annunci

#CRM2016 – Get all teams by user in C#

public Microsoft.Xrm.Sdk.EntityCollection UserTeams(Guid UserID)
{

    QueryExpression query = new QueryExpression("team");
    query.ColumnSet = new ColumnSet(true);
    LinkEntity link = query.AddLink("teammembership", "teamid", "teamid");
    link.LinkCriteria.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, UserID));

    try
    {
      return service.RetrieveMultiple(query);
    }
    catch (Exception ex)
    {
       // Do your Error Handling here
       throw ex;
    }
}

CRM2016 – Check if User is a member of a team C#

The code is the following:

public static bool IsTeamMember(Guid teamID, Guid userID, IOrganizationService service)
{
QueryExpression query = new QueryExpression("team");
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, teamID));
LinkEntity link = query.AddLink("teammembership", "teamid", "teamid");
link.LinkCriteria.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, userID));
var results = service.RetrieveMultiple(query);

if (results.Entities.Count > 0)
{
return true;
}
else
{
return false;
}
}