Skip to main content

Qlik Sense: Connect to .NET SDK with dynamic header authentication

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Damien_Villaret
Support
Support

Qlik Sense: Connect to .NET SDK with dynamic header authentication

Last Update:

Feb 23, 2021 4:11:17 AM

Updated By:

Sonja_Bauernfeind

Created date:

Mar 14, 2018 9:24:10 AM

This is an example of how to connect to Qlik Sense using Dynamic header authentication with the .NET SDK

The following must be installed to test the example provided in this article:

  • Microsoft Visual Studio (The community version can be used)
  • Qlik Sense Server


*It does not need to be installed on the same machine, but proper ports must be open for incoming connection on the Qlik Sense server side.
*Qlik Sense certificates need to be installed on the machine running Microsoft Visual Studio for the connection to be trusted.

Environments:

Qlik Sense Enterprise any version

 

Resolution:


The example below is created based on the console application (.NET framework) template. Please note that the Qlik Sense .NET SDK also need to be installed. (For details, see Qlik Sense: Getting started with the .NET SDK )
 

using System;
using Qlik.Engine;
using Qlik.Engine.Communication;

namespace ConnectServerNTLM
{
    class Program
    {
        static void Main(string[] args)
        {
            var uri = new Uri("https://qlikserver1.domain.local");

            if (args.Length > 0)
            {
                uri = new Uri(args[0]);
            }
            ILocation location = Qlik.Engine.Location.FromUri(uri);
            location.CustomUserHeaders.Add("hdr-usr", "DOMAIN\\myuser2");
            location.AsNtlmUserViaProxy();
            location.VirtualProxyPath = "hdr";

            PrintQlikSenseVersionNumber(location);
        }
        
        private static void PrintQlikSenseVersionNumber(ILocation location)
        {
            try
            {
                using (IHub hub = location.Hub(noVersionCheck: true))
                {
                    Console.WriteLine(hub.ProductVersion());
                }
            }
            catch (CommunicationErrorException cex)
            {
                Console.WriteLine("Can not connect to Qlik Sense instance, check that Qlik Sense is running." + Environment.NewLine + cex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("General error." + Environment.NewLine + ex.Message);
            }
            Console.ReadLine();
        }
    }
}


On the Qlik Sense side, a virtual proxy with dynamic header authentication needs to be configured correctly. See below an example of configuration:

AUTHENTICATION
Anonymous access mode: No anonymous user
Authentication method: Header authentication dynamic user directory
Header authentication header name: hdr-usr
Header authentication dynamic user directory: $ud\\$id



 

Labels (1)
Contributors
Version history
Last update:
‎2021-02-23 04:11 AM
Updated by: