Apr 23

Written by: Michael Washington
4/23/2011 1:57 PM  RssIcon

NOTE: Please see Easy DotNetNuke LightSwitch Deployment, for an easier method to use LightSwitch in a DotNetNuke website

DotNetNuke has long been known as one of the easiest and most powerful web content management frameworks.

Combined with LightSwitch, the easiest way to create data driven applications, you have the ability to create and deploy “Line-Of-Business” applications quickly and easily.

An important thing to note, is that you can use your existing DotNetNuke users and roles with your LightSwitch applications.

This is really important if your already have accounts and roles.

You don’t want to require your users to learn a new username and password, and need to log into, each application.

Deploying your LightSwitch applications in DotNetNuke allows a seamless user experience.

What You Need:

  • DotNetNuke 5 (using ASP.NET 4.0)
  • LightSwitch Beta 2 (or higher)
  • Visual Studio 2010 Standard (or higher)
  • If you want to deploy your website on a Windows 7 machine, you need to have Windows Ultimate installed

 

Create the LightSwitch Application

image

The first step is to create a simple LightSwitch application that will track a user’s Tasks.

image

We wire-up the ‘Created’ event for the Entity.

image

… and add a single line of code to the Task_Created method, that will set the Username field to the “Application.User.Name”.

When this application is running inside of DotNetNuke, it’s Membership Provider will provide this username.

This is all that is required to integrate into DotNetNuke security.

image

In the Properties, ensure that the application is using Forms Authentication.

image

Also ensure that it is set as a web application, hosted in IIS.

image

Next, from the Menu bar, we select Build, then Configuration Manager.

image

… and set the configuration to Release. This will prevent the button for the screen designer from appearing on the deployed application.

image

We select Build, then Publish.

image

We then use the wizard to deploy the application.

image

Note: you can download the Visual Studio LightSwitch Application at this link.

The DotNetNuke Site

To integrate the LightSwitch application into a DotNetNuke site, we must first, do these things:

  • Use the latest version of DotNetNuke 5
  • Run the site using ASP.NET 4.0

 

image

 

Now, we install the following module (at this link).

 

image

This module runs a script, that creates a table called ‘RolePermissions’ that LightSwitch expects to be part of the Membership Provider.

DotNetNuke uses a custom membership provider, and does not use that table, but, it needs to be there or it will throw an error.

The module also dynamically injects the .xap file and the JavaScript needed.

It contains the .xap used in this example LightSwitch project, but you can update the code to reference your own .xap.

image

Next, we go to the deployed LightSwitch application and script out any tables that are part of the application

(we do not script out the tables that are part of the ASP.NET membership provider, so in this case we only script out the Tasks table).

image

While logged in as Host on the DotNetNuke site, we select Host, then SQL.

image

We run the script to create the table(s).

image

Next, we copy all the folders and .dll’s from the “Bin” directory of the deployed LightSwitch application, to the “Bin” directory of the DotNetNuke website.

image

Copy the “Web” folder from the deployed LightSwitch application, to the root directory of the DotNetNuke website.

Remove the .xap file that is in the “Web” directory,

because it is now in the “…\DesktopModules\LightSwitchModule\ClientBin\” directory

(it was placed there when we installed “LightSwitchModule_01.00.00_Install.zip”).

image

Copy the ClientAccessPolicy.xml file from the deployed LightSwitch application, to the root directory of the DotNetNuke website.

 

Update the DotNetNuke Web.config

First, backup the existing DotNetNuke Web.config file.

It may also help to open the DotNetNuke site up in Visual Studio 2010 at this point because it will provide intellesense when making changes to the web.config.

Change:

  <system.webServer>
    <modules>

To:

    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true">

Add the following sections to the web.config:

<configuration>	
	<connectionStrings>		
		
		
		
		<add name="_IntrinsicData" connectionString="{set this to the same settings as the SiteSQLServer Connection string}" providerName="System.Data.SqlClient"/>
	connectionStrings>
	<appSettings>

		
		
		
		<add key="UserCodeAssemblies" value="Application.Common.dll;DNNLightSwitchTasks.Server.dll;DNNLightSwitchTasks.ServerGenerated.dll"/>
		<add key="ExtensionAssemblies" value="Microsoft.LightSwitch.Extensions.Server.dll"/>
		
		<add key="Microsoft.LightSwitch.Trace.Enabled" value="false"/>
		
		<add key="Microsoft.LightSwitch.Trace.LocalOnly" value="true"/>
		
		<add key="Microsoft.LightSwitch.Trace.Level" value="Information"/>
		
		<add key="Microsoft.LightSwitch.Trace.Sensitive" value="false"/>
		
		<add key="Microsoft.LightSwitch.Trace.Categories" value="Microsoft.LightSwitch"/>
		
		<add key="Microsoft.LightSwitch.RequireEncryption" value="false"/>
	appSettings>
	<system.webServer>
		<modules runAllManagedModulesForAllRequests="true">
			
			
			
			<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add name="ServerHttpModule" preCondition="managedHandler" type="Microsoft.LightSwitch.WebHost.Implementation.RedirectToHttpsModule,Microsoft.LightSwitch.Server.Internal,Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
		modules>
	system.webServer>
	
	
	
	<system.serviceModel>
		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
		<behaviors>
			<serviceBehaviors>
				<behavior name="">
					<dataContractSerializer maxItemsInObjectGraph="6553600"/>
				behavior>
			serviceBehaviors>
		behaviors>
	system.serviceModel>
	<system.web>
    		
    		
    		
    		<trace enabled="true" localOnly="true" requestLimit="40" writeToDiagnosticsTrace="false" traceMode="SortByTime" mostRecent="true" />
    		<httpModules>        
			
			
			
			<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add name="ServerHttpModule" type="Microsoft.LightSwitch.WebHost.Implementation.RedirectToHttpsModule,Microsoft.LightSwitch.Server.Internal,Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
		httpModules>
		<httpHandlers>
      			
      			
      			
      			<add verb="GET" path="trace.axd" type="Microsoft.LightSwitch.WebHost.Implementation.TraceHandler,Microsoft.LightSwitch.Server.Internal,Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    		httpHandlers>
		<compilation>
			<assemblies>
				
				
				
				<add assembly="Microsoft.LightSwitch.Base.Server, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      			assemblies>
  		compilation>    
		
		
		
		<roleManager enabled="True" defaultProvider="AspNetRoleProvider">
			<providers>
				<clear/>
				<add name="AspNetRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="_IntrinsicData" applicationName="DotNetNuke"/>
			providers>
		roleManager>
		<profile enabled="True" defaultProvider="AspNetProfileProvider">
			<providers>
				<clear/>
				<add name="AspNetProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="_IntrinsicData" applicationName="DotNetNuke"/>
			providers>
			<properties>
				<add name="FullName"/>
			properties>
		profile>
	system.web>
configuration>

 

On the _IntrinsicData key, make sure you replace {set this to the same settings as the SiteSQLServer Connection string} with the value of the existing SiteSQLServer key.

 

image

 

While logged into your DotNetNuke site as the Host or an Administrator, place the LightSwitchModule on a page in your DotNetNuke site.

 

image

The module will now work.

 

Trouble Shooting

(note: do not send me a personal email asking for help. It will go unanswered because there is no way for me to help everyone personally. Please post to the forums. Thank You!)

If you get the Load operation failed for query ‘GetAuthenticationInfo’. The remote server returned an error: NotFound. error :

image

LightSwitch is getting an error when it is trying to go to this address:

http://{Your DotNetNuke Site}/DesktopModules/LightSwitchModule/ClientBin/Microsoft-LightSwitch-Security-ServerGenerated-Implementation-AuthenticationService.svc/binary/GetAuthenticationInfo

If you go to that address and get the following error:

image

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.

You need to follow the direction on this page to resolve it:

http://msdn.microsoft.com/en-us/library/x8a5axew.aspx

Note: If you are running this on a machine using the Windows 7 operation system, you MUST have Windows 7 Ultimate for this to work, period. For an explanation, see this post.

NOTE: Please see Easy DotNetNuke LightSwitch Deployment, for an easier method to use LightSwitch in a DotNetNuke website

7 comment(s) so far...


Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

Is there _any_ way you can fix the formatting to get rid of the horizontal scrolling? The post is rather unreadable.

By Jonathan on   4/25/2011 9:35 AM
Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

@Jonathan - Because these are web.config keys that must be correct, I did not want to risk putting in line breaks. I agree that the scrolling is painful :(

By Michael Washington on   4/25/2011 9:38 AM
Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

Michael,

Other than DotNetNuke 5 and ASP.NET 4.0, are there other requirements on the server?
Is DotNetNuke 6 OK? Is IIS 7.0 OK? Is SQL Server 2008 R2 OK? (These are what my
hosting provider has available, along with ASP .NET 4.0.) Clearly for now, there is no
direct LightSwitch deployment option for DoNetNuke. In your deployment example's
"LightSwitch Publish Application Wizard" screen image, you show the data base as
"(local)/LightSwitch," which I take to be local to your development machine. Is the same
true with IIS? Is that deployment local or does that go directly to the DotNetNuke host?
I want to clearly understand what is "local" and what is not, according to your example.
Do you think your DotNetNuke deployment example will work with any hosting provider
that claims they fully support DotNetNuke? What about hosting providers that only allow
"medium trust" levels, which is typical. I am using a shared Go Daddy hosting account and
have no access to admin, executables, root configuration files, or the underlying server for
that matter (which is typical of shared hosting). I only see my alloted IIS website space.
Please let me know if LightSwitch, and your DotNetNuke deployment method is for my
situation.

Thanks.

By LarryT on   9/15/2011 8:35 PM
Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

@LarryT - Look at the method used at: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/29/Easy-DotNetNuke-LightSwitch-Deployment.aspx

By Michael Washington on   9/15/2011 8:38 PM
Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

Michael,

Do you have a VB version of your sample? We have successfully built upon your C# sample and got things working in a new environment and was wondering whether a VB equivalent was available.

Many Thanks,
James Black
Intechrity

By James Black on   4/3/2012 5:10 PM
Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

@James Black - Sorry no VB version.

By Michael Washington on   4/3/2012 5:11 PM
Gravatar

Re: Deploy Your LightSwitch Application As A DotNetNuke Module

Michael,
I have tried to build the application using Visual Basic and then C# using your instructions on this page.

When I copy everything over I get this error:

Model loading failed. There is no ApplicationDefinitionLoader in the composition.
Inner exception message:
There is no ApplicationDefinitionLoader in the composition.

I have done a trace and it is not showing anything.

Can you think of anything different that you did for your sample app? I can get that to work and I can do advanced extensions to it. However, our company policy is VB and we would really love to get this working.

Many thanks, James

By James Black on   4/4/2012 4:13 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation