Share via


Alternative Hosting

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Silverlight is primarily designed for hosting in a Web page. However, there are several alternative hosting options that enable Silverlight to run outside the browser or within another host environment.

Most alternative hosting options are outside the scope of the Silverlight documentation. However, this topic summarizes the options and provides links to additional information and sample code where available. In particular, the Silverlight Alternative Hosting page on the MSDN Code Gallery provides additional documentation and code samples for some advanced hosting options.

This topic contains the following sections:

  • Using Silverlight Outside the Browser

  • Using Silverlight in a Browser Control

  • Using a Silverlight User Interface in Another Plug-In or Application

  • Using Silverlight in a Windows-Based Application through COM

  • Using Silverlight in Another Application through the Browser Interface

NoteNote:

Silverlight is subject to the same security sandbox restrictions regardless of the host environment or the presence of a Web browser. However, the host environment could provide full access to the local computer, effectively bypassing Silverlight security.

If a browser or network connection is not present, the host environment might have to provide replacement functionality depending on your requirements.

Using Silverlight Outside the Browser

Silverlight provides basic out-of-browser support on Windows and Macintosh computers for your Web-hosted, Silverlight-based applications. This is the easiest way to use Silverlight outside a Web browser, but it requires that users install the application from a host Web page.

For more information, see Out-of-Browser Support.

For richer offline support, including full access to the local computer, consider using Windows Presentation Foundation (WPF). WPF provides a superset of Silverlight functionality and enables you to convert your Silverlight-based applications to full-featured Windows applications with minimal code modifications.

For more information, see Windows Presentation Foundation.

Using Silverlight in a Browser Control

Using an embedded Web browser control is the easiest way to add Silverlight to an application that was created with another technology. In this case, your application hosts a browser control, which displays a Web page, which in turn hosts your Silverlight-based application.

Depending on your needs, you can hide the boundaries between the hosting layers and create a seamless user interface. To communicate between your host application and your Silverlight code, you can use the HTML DOM.

For information about how to access the HTML DOM from Silverlight, see HTML Bridge: Interaction Between HTML and Managed Code. To access the DOM from your host application, consult the documentation for your chosen browser control. The following list indicates some common browser controls.

Using a Silverlight User Interface in Another Plug-In or Application

Silverlight provides an unmanaged interface named ISilverlightViewer through which you can retrieve a bitmap rendering of a Silverlight-based user interface (UI). You can use this functionality to combine Silverlight UI elements with the UI of another application.

In this scenario, you typically embed the Silverlight plug-in behind the UI of the host plug-in or application. The host can then display specific parts of the Silverlight UI and receive any corresponding mouse and keyboard user input. Because the Silverlight UI can change in response to user input, the host will typically display rendering updates continually.

This hosting alternative is particularly useful for displaying Silverlight UI elements within another browser plug-in. In this case, the host plug-in can interact with Silverlight entirely through the ISilverlightViewer interface, while the browser handles the embedding details. Without the browser present, the host application must use another hosting option, possibly in addition to accessing the ISilverlightViewer interface.

The Silverlight Alternative Hosting page provides additional documentation for this hosting option, including sample code.

Using Silverlight in a Windows-Based Application through COM

Silverlight provides several COM interfaces through which a Windows-based application can host the Silverlight plug-in. This approach provides significant flexibility, but also requires significant development effort.

With this option, your host application must provide the necessary COM hosting infrastructure, and must implement the IXcpControlHost and IXcpControlHost2 interfaces. You can then interact with the Silverlight plug-in through the IXcpControl and IXcpControl2 interfaces.

With Silverlight 4, you can host trusted applications and implement the IXcpControlHost3 interface to fulfill plug-in requests for Automation objects. For more information, see Trusted Applications and the COM Reference.

The COM hosting mechanism was designed to meet specific needs, and currently has a number of limitations. For example, you can invoke handlers in your host application only for JavaScript API events in your Silverlight code, but not for managed API events. For more information about the JavaScript API, see JavaScript API for Silverlight.

The Silverlight Alternative Hosting page provides additional documentation for this hosting option, including sample code. For more information about the Silverlight COM interfaces, see the COM Reference.

Using Silverlight in Another Application through the Browser Interface

One final option is to host the Silverlight plug-in through the browser plug-in model. In this scenario, your host application assumes the role of the browser and embeds the Silverlight plug-in the same way a browser does.

This option provides relatively integrated access for Macintosh-based applications, where the COM interfaces are not available. In this case, you will typically use the NPAPI interface (also known as the Gecko Plugin API). For more information, see the Gecko Plugin API Reference.

This is an advanced hosting option for which there is currently no additional guidance.