logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
martin_mcmahon  
#1 Posted : Friday, February 2, 2018 4:21:13 PM(UTC)
martin_mcmahon


Rank: Guest

Joined: 5/19/2017(UTC)
Posts: 2
Ireland

Hi there,

We're receiving the string "null" from one of our extensions after upgrading to 6.4 from an older version.
This extension is supposed to return a URL to the caller.

The funny thing is - calling this extension from Postman works, however calling it using a HttpClient class in C# is where
we get the string "null" returned in a response.

Code below - much appreciate any insights you may have.

Thanks,
Martin.

Code:

%@ WebHandler Language="C#" Class="Service" %>

using System;
using System.Security;
using System.Configuration;
using System.Web;
using System.Linq;
using System.Net;
using System.Collections.Generic;
using ScreenConnect;

public class Service : WebServiceBase
{
	public string GetLaunchUrl(string sessionName, int exTime, string browser, string userDisplayName )
	{
        DateTime expireTime = DateTime.Now.AddMinutes(exTime);
        string handlerUrl = null;
        IEnumerable<ScreenConnect.PermissionEntry> permissionEntries = null;
        string sessionFilter = ServerExtensions.GetExpression("Name", "=", sessionName);
        UriBuilder relayUri = ServerExtensions.GetRelayUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, true);
        Dictionary<string,string> variables = ServerExtensions.GetStandardVariables((string)userDisplayName);
        string scURL;

		// Sanity check on called parameters
		if (String.IsNullOrEmpty(sessionName) || String.IsNullOrEmpty(browser) || exTime == 0 || String.IsNullOrEmpty(userDisplayName))
		{
			throw new ArgumentException("Invalid or null arguments passed");
		}
		
		if (browser.Contains("Chrome") || browser.Contains("Firefox")) {
			handlerUrl = new Uri(HttpContext.Current.Request.Url, HttpRuntime.AppDomainAppVirtualPath) + WebConfigurationManager.GetHandlerPath(typeof(ClickOnceRunHandler)).ReplaceFirst("*", WebResources.GetString("FileDownload.BaseName"));
		}
		
		else if (browser.Equals ("IE"))
		{
			handlerUrl = new Uri(HttpContext.Current.Request.Url, HttpRuntime.AppDomainAppVirtualPath) + WebConfigurationManager.GetHandlerPath(typeof(ClickOnceDirectHandler)).ReplaceFirst("*", WebResources.GetString("FileDownload.BaseName"));
		}
		
		else if (browser.Equals ("Mac"))
		{
			handlerUrl = new Uri(HttpContext.Current.Request.Url, HttpRuntime.AppDomainAppVirtualPath) + WebConfigurationManager.GetHandlerPath(typeof(ClickOnceDirectHandler)).ReplaceFirst("*", WebResources.GetString("FileDownload.BaseName"));
		}
		
		else // If we don't know what the browser is, throw exception
		{
			throw new Exception("Unrecognised browser");
		}
		
		
		// Get user display name and permissions
        try
        {
        	permissionEntries = Permissions.GetEntriesForUser();
        	Permissions.AssertPermission(new PermissionRequest(), true);
        }
        catch(Exception e)
        {
        	throw new Exception("Error getting user details from SC: " + e.Message);
        }
        
        // Generate SC URL
        try
        {
        	sessionFilter = ServerExtensions.GetExpression("Name", "=", sessionName);
        	relayUri = ServerExtensions.GetRelayUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, true);
        	variables = ServerExtensions.GetStandardVariables((string)userDisplayName);
        	
        	scURL = (from session in SessionManagerPool.Demux.GetSessions(sessionFilter)
             from groupContainingSession in SessionManagerPool.Demux.GetSessionGroupsContainingSession(session.SessionID, variables)
             where Permissions.HasPermission(new SessionPermissionRequest { Name = PermissionInfo.ViewSessionGroupPermission, SessionType = session.SessionType, SessionGroupName = groupContainingSession }, permissionEntries)
             let sessionPermissions = PermissionInfo.GetSessionPermissions(permissionEntries, session.SessionType, groupContainingSession, session.Host == userDisplayName)
             select new ClientLaunchParameters
             {
                 Host = relayUri.Host,
                 Port = relayUri.Port,
                 EncryptionKey = ServerCryptoManager.Instance.PublicKey,
                 SessionType = session.SessionType,
                 SessionID = session.SessionID,
                 ProcessType = ProcessType.Host,
                 SessionTitle = session.Name,
                 AccessToken = ServerCryptoManager.Instance.GetAccessToken(session.SessionID, ProcessType.Host, userDisplayName, sessionPermissions, expireTime),
             })
            .FirstOrDefault()
            .SafeNav(clp => handlerUrl + ClientLaunchParameters.ToQueryString(clp))
            .Else(default(string));
        }
        catch(Exception e)
        {
        	throw new Exception("Error creating launch link: " + e.Message);
        }
        
        return scURL;
	}
}
Scott  
#2 Posted : Monday, February 5, 2018 12:31:06 PM(UTC)
Scott


Rank: Administration

Medals: Level 4: Wise Old Owl! Received 100 Thanks!

Joined: 3/28/2014(UTC)
Posts: 2,566
United States

Thanks: 3 times
Was thanked: 313 time(s) in 270 post(s)
I don't see anything obviously wrong with the method so I'm inclined to look at how the call is being made from the HttpClient you describe.

Can you use wireshark or network monitor to compare calls made from it and from postman? It might be something as simple as an incorrect header.
ScreenConnect Team
martin_mcmahon  
#3 Posted : Monday, February 5, 2018 1:12:00 PM(UTC)
martin_mcmahon


Rank: Guest

Joined: 5/19/2017(UTC)
Posts: 2
Ireland

Thanks for looking over the code Scott. I've tried the C# standard HttpClient and also tried Resharper - both are getting the same "null" string.
Good idea on wireshark - I'll give that and fiddler a try to see if anything appears.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.