How to use previously Out-of-Browser-only features in LightSwitch for In-Browser Apps with VS 11 Beta

With LightSwitch for Visual Studio 11 Beta, the client is now built using Silverlight 5.  One of the capabilities new to SL 5 is the ability to access certain classes and methods In-Browser that were previously only accessible Out-of-Browser.

Before proceeding, you should know that there are a few caveats.  One is that you need to change some registry settings on each client machine to enable Elevated Trust applications to run In-Browser.  Alternatively you can use Group Policy settings to accomplish this.  Also, clients must use Internet Explorer.  Finally, you must sign your XAP and be sure that the signing certificate is installed in the Trusted Root Certification Authorities store.  You can find more information about these requirements here.

With vanilla Silverlight 5 applications, you can go to the application properties page and check “Require elevated trust when running in-browser”.

This setting, however, is not surfaced from the Visual Studio UI when working with a LightSwitch application.  So for LightSwitch, you’ll need to edit the csproj file manually.  Make sure your solution is closed in VS and find the csproj (or vbproj) file in the Client folder of your LS project.  Find the <OutOfBrowserSettingsFile> line and add this line below it:

<InBrowserSettingsFile>Properties\InBrowserSettings.xml</InBrowserSettingsFile>


Save the file, then in the Properties folder, create this InBrowserSettings.xml file:

<InBrowserSettings>
  <InBrowserSettings.SecuritySettings>
    <SecuritySettings ElevatedPermissions="Required" />
  </InBrowserSettings.SecuritySettings>
</InBrowserSettings>

With that done, you should be able to make use In-Browser of the WebBrowser control, the Office Integration Pack, and many other controls previously restricted to Out-Of-Browser apps.

  • https://www.facebook.com/nesticle8bit Julio Poveda

    Hi, so many thanks for this :) , take a look of this line:

    PropertiesInBrowserSettings.xml

    should be:

    PropertiesInBrowserSettings.xml

    Thanks again Jewell

    • Jewel Lambert

      Thanks for the correction! There were a few early posts where the code got a bit garbled when I migrated to a new web server – must’ve missed this one.

  • Gaelan Brewer

    This is a great post and works perfectly while debugging in visual studio, but unfortunately, ounce I publish the app to IIS the “WebBrowser is enabled only for Out-of-Browser applications …” warning message pops back up. Is there anything else I need to do in IIS or during publishing to retain the ElevatedPermissions setting?

    Thanks again for the slick trick, its a total windfall for embedding SSRS reports in my Lightswitch apps.

    P.S.
    Developed in Visual Studios 2013
    Deployed to MS Server 2012