Deep Linking Between Lightswitch HTML and Silverlight Clients

Update 7 Nov 2013: This article is now out-of-date, since the LightSwitch HTML Client now has built-in support for deep-linking. 

 

Suppose you have both a Silverlight client and an HTML client in your Lightswitch project, and you’d like to be able to navigate between them. In particular, from the Silverlight client you’d like to be able to navigate directly to a particular screen and entity in the HTML client, and vice versa.

One way to accomplish this have a home screens in both clients which look at the parameters passed in the URL and redirect to the appropriate screen and entity. So to navigate to Account Id 100 on the AccountDetail screen of your Silverlight Client, you could go directly to the URL: http://mydomain.com/DesktopClient/?screen=AccountDetail&id=100

Similarly, to navigate to the ViewAccount screen of your HTML Client, you could go to the URL: http://mydomain.com/HTMLClient/?screen=ViewAccount&id=100

You can download a sample project here.


The essential code is in the created method of the HTML Client’s home screen:

myapp.Home.created = function (screen) {
    // current navigation action hasn't completed, so we need to
    // fire other navigation actions after a timeout
    setTimeout(function () {
        // parse the URL to get the 'screen' and 'id' parameters, if present
        var screenName = dotnetlore.utils.getUrlParameter('screen'),
            id = dotnetlore.utils.getUrlParameter('id');

        // depending on these parameters, redirect to the appropriate screen and entity
        if (screenName === 'ViewAccount' && id > 0) {
            myapp.activeDataWorkspace.ApplicationData.Accounts_SingleOrDefault(id).execute().then(function (data) {
                if (data && data.results && data.results[0]) {
                    myapp.showViewAccount(data.results[0]);
                }
            });
        }
    }, 0);
};

and in the InitializeDataWorkspace method of the Silverlight client’s Home screen:

string screenName;
string idString;
QueryStringHelper.TryGetValue("screen", out screenName);
QueryStringHelper.TryGetValue("id", out idString);
if (screenName != null)
{
	if (screenName == "AccountDetail")
	{
		int id;
		int.TryParse(idString, out id);
		if (id != null)
		{
			this.Application.ShowAccountDetail(id);
		}
	}
}

 

  • Rom’s

    Hi Jewel,

    Nice tip but I have a problem with your solution. When I click on the button from my command bar of the HTML Client to go on the Silverlight Client, I have this error : “Load operation failed for query ‘GetAuthenticationInfo’. The remote server returned an error: NotFound.”.

    Can you help me please?

    Thank you in advance.

    • Jewel Lambert

      I’ve never encountered that error myself, so I’m not sure what to suggest.

      Is the silverlight client the startup client?
      Does it work if you enter the URL directly in your browser instead of clicking the button?
      Is authentication off for your Lightswitch app?
      There are a number of MSDN forum posts on that issue, see here:
      http://goo.gl/5f28R

      Also, there was an issue with DevExpress XtraReports that caused that error:
      http://www.devexpress.com/Support/Center/Question/Details/Q434921

      • Rom’s

        My startup client is the HTML client and I use forms authentication. When I enter the URL directly I have the same error.

        I will see the links that you recommend.
        Thank you.

  • Garth Henderson

    This is very helpful. Many thanks!

  • Ashok Sharma

    I am trying to get deep-linking to work on my application. The first error I get while deep linking to HTML Client is:

    The DOM/scripting bridge is disabled.

    Also when HTML CLient is a startup client, the application is unable to find ‘dotnetlore’

    Appreciate your comments/guidance here.

    Thanks a lot
    Ashok