Friday, July 31, 2020

SharePoint DevOps tasks

These are the tasks generally required for building a sharepoint add-in successfully in Azure DevOps:

  • Use vs2017-win2019 agent in devops build pipeline due to sharepoint.targets error
  • ASP.Net website
    • Set output directory to 'bin\' rather than 'bin\debug'
      • Open project property pages (right click -> properties)
      • Open Build tab
      • Set the 'Output Path' property to 'bin\'
      • https://docs.microsoft.com/en-us/visualstudio/ide/how-to-change-the-build-output-directory?view=vs-2019
    • Build Pipeline
      • Add three publishing profiles with following settings

Variable

DEV

Publish Method

Web Deploy

Server

<Dev IIS Server name>

Site Name

 

User Name

<user name>

Destination Url

 

Configuration

Debug

Db connection string

#{connectionstring1}#


  • Remove Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime dlls and add packages SharePoint.Client and SharePoint.Client.Runtime from nuget
  • Add Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime dlls to sourcecontrol
  • Use nuget.config in restore nuget packages task
  • Add Microsoft.IndetityModel.dll and Microsoft.IndetityModel.Extensions.dll to source control
  • Replace AppForSharePoint16WebToolkit v4.0 with v.3.1.5
  • Add publishing profiles to source control
  • Sharepoint addin project
    • Add a list to make sure app web is provisioned

Thursday, July 30, 2020

msdeploy to a remote server

If we want to publish files to a remote iis server, msdeploy can be used in a format similar to:


msdeploy.exe 
    verb:sync 
    -source:contentPath="C:\temp\files-to-pub" 
    -dest:contentPath='sayedupdemo/files-to-pub'
            ,ComputerName="https://waws-prod-blu-001.publish.azurewebsites.windows.net/msdeploy.axd?site=sayedupdemo"
            ,UserName='$sayedupdemo'
            ,Password='thisIsNotMyRealPassword'
            ,AuthType='Basic'

Tuesday, July 28, 2020

Azure Build react native app with gradle

I found this blog explains the steps to build a react native app with gradle in azure ci/cd pipelines. The only confusion was regarding keystore files, after searching a bit on internet I realized that keystore files can have both .keystore and .jks extension.

https://techcommunity.microsoft.com/t5/windows-dev-appconsult/using-azure-devops-to-create-a-ci-cd-pipeline-for-an-android/ba-p/1094422

Monday, July 27, 2020

SharePoint: Invalid SP Host Web Token - RedirectionStatus is CanNotRedirect after CheckRedirectionStatus

This is one of the most confusing errors I have seen, not because the error message is ambiguous, but rather because it was difficult to find the root cause (at least for me anyway).

This error is thrown at the code in sharepoint context filter:


switch (SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext, out redirectUrl))
            {
                case RedirectionStatus.Ok:
                    ok = true;
                    break;
                case RedirectionStatus.ShouldRedirect:
                    filterContext.Result = new RedirectResult(redirectUrl.AbsoluteUri);
                    break;
                case RedirectionStatus.CanNotRedirect:
                    throw new Exception("Invalid SP Host Web Tocken");
            }


Redirection status is determined in SharePointContextProvider class at this line:


if (StringComparer.OrdinalIgnoreCase.Equals(httpContext.Request.HttpMethod, "POST"))
            {
                return RedirectionStatus.CanNotRedirect;
            }


Though this sound bit un-intuitive, this error is caused by AnonymousAuthentication property set to the value 'Enabled'.

Wednesday, July 15, 2020

Claims Identity - Extract UPN from a claim (IIdentity)

A claim with the type IIdentity can contain multiple claims and quite often we may need to extract the value of a particular claim within. This is fairly simple like so:

var email = principal.FindFirst(ClaimTypes.Upn)?.Value;

Reference: https://docs.microsoft.com/en-us/azure/architecture/multitenant-identity/claims

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...