LightSwitch with Oracle Data Source (part 2)

External login and global parameters

In the previous part I mentioned I’m working on existing database, changing the application administration. One of the issues I have to solve is using  the existing authentication. LightSwith has build in authentication, but it uses .NET Role and Membership providers and they are not solution we choose for Oracle database when we started the project long time ago.

This post is about implementing external authentication in both Silverlight and HTML LightSwitch clients. Also I will implement some roles and some data filtering connected with the existing authentication used in this project.

There is one condition – the project have to be converted to the new version, because in the old LightSwitch you don’t have access to default.html file.

For implementing a scenario like this you have to disable the authentication in LightSwitch from project properties.

The next step is not to switch into File View mode and add Generic Handler. I place it in a sub-folder to keep the code clean.

p2 AddSessionService

The code in this file shall be designed according to your product structure.

(this is only an example of the file possible structure returning a hard-coded successful login response for test purpose only)

After building the server side for authentication I needed to deliver the session ID into the Silverlight client. The best way to deliver values in Silverlight is through initParams in the HTML. For this to work change the default.html in the client. Maybe the final version will include default.aspx or else where I can generate the content, but for this example I will hard-code this too.

<div id=”silverlightControlHost”>
<object ID=SilverlightApplication data=”data:application/x-silverlight-2,” type=”application/x-silverlight-2″ width=”100%” height=”100%” >
<param name=”source” value=”Web/vSchool.Client.xap”/>
<param name=”onerror” value=”onSilverlightError” />
<param name=”background” value=”white” />
<param name=”minRuntimeVersion” value=”5.0.61118.0″ />
<param name=”autoUpgrade” value=”true” />
<param name=”initParams” value=”sid=1276527327723″ />
              <a href=”″ style=”text-decoration: none;”>
<img src=”″ alt=”Get Microsoft Silverlight” style=”border-style: none”/>
<iframe style=’visibility:hidden;height:0;width:0;border:0px’></iframe>


Switch back to Logical View and then open any screen. From Write Code  drop down select any ‘*_Run’ function and this will open the Application class.

In the Application class I add some global parameters:

Initialization of the LightSwitch Application Client have to make a call to the Service I made in Server part for validating the session. The process of initialization have to wait until communication is completed.

The WebClient completed event handler:

In this solution I used a method called GetBaseAddress for generating the server address

HTML client will work more fluent with external calls, because it is not seal in Silverlight. We can call server at any time with AJAX, but what I did was to add global parameters in default.html and call service only once.

Inside default.html

I added a screen without attached table or query and I name it Home. My intentions are to use this screen as menu page by adding some buttons. Each button will open a screen with list or details. But, first I will check for the session.

When designing the home screen add a Post Render Code …


The code behind is simple:

  • read session ID from query string params ( with function getParameterByName(name));
  • AJAX call the session check service;
  • parse the results ( with function getResponceParamByName(response,name));


All this was about how to assign external authentication. The hard pars is up a head.

The LightSwitch shall work only with queries where parameters collected from external authentication are counted in.

Each time when creating a query assign the global parameters as required and then by clicking on PreprocessQuery in Write Code implement the query code.



The code in the query shall look like this:

From this example is visible that the filtering parameter is not used against the queried table, but to a linked table. So, this is flexible enough to work with almost any existing project.

Adding this query to a screen will create a filtering parameter on top (above the list). Hide or remove the field visualization and change the InitializeDataWorkspace code to set the value from the global params list.

Silver light example:

For HTML change ‘created’ event. For example:

I will not go into details about how you can implement role validation because it’s same as it’s designed by LightSwitch, except I’m using my global parameters instead of ‘Permissions’ object. And because it only work on client side (for now)



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.