Bagikan melalui


Integrating Silverlight with a Web Page

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

You can embed the Silverlight plug-in in your Web page in one of two ways:

  • Using the HTML object element.

  • Using the Silverlight.js helper file.

The HTML object element is compatible with all supported Web browsers, and provides the basis for the Silverlight.js embedding technique. The Silverlight.js embedding functions ultimately generate HTML object elements, and expose all the features that the object element exposes. This common basis enables you to combine both embedding techniques.

NoteNote:

In order to support Silverlight-based applications, your Web server must be configured to associate the .xap file name extension with the MIME type "application/x-silverlight-app". For IIS 7.0 or later, this value is pre-configured.

The following sections provide a brief overview of the available embedding and integration options. Each section includes links to topics with additional details.

Using HTML

The HTML object element is the simplest way to embed the Silverlight plug-in, and is the recommended way. This is the default approach that is used by Visual Studio when you create a new Silverlight-based application and choose to host it in a dynamically generated HTML page.

You can use the object element to integrate Silverlight with JavaScript code in your Web page. However, JavaScript is not required to embed the control. This is useful if JavaScript is disabled on the client or prohibited on the server.

For more information, see How to: Add Silverlight to a Web Page by Using HTML.

Using JavaScript

The Silverlight.js file is not required to integrate Silverlight with JavaScript. However, it provides embedding functions for convenience when you use JavaScript.

Silverlight.js is primarily useful to enable a JavaScript-enhanced Silverlight installation experience. You can take advantage of these features even when you use the HTML object element to embed the plug-in.

For more information about using the embedding functions, see How to: Add Silverlight to a Web Page by Using JavaScript. For more information about Silverlight.js, see Silverlight.js Reference.

ASP.NET Integration

Previous versions of the Silverlight SDK included the ASP.NET Controls for Silverlight. These enabled a way for Silverlight applications to be embedded in an ASP.NET Web page that is familiar to ASP.NET developers. The Silverlight SDK no longer contains the ASP.NET Server Controls for Silverlight and developers are encouraged to use the HTML or JavaScript embedding techniques described previously to add Silverlight content.

For more information about upgrade scenarios, see ASP.NET Support for Silverlight.

Providing a Custom Installation and Upgrade Experience

The Silverlight project templates for Visual Studio currently provide a very simple default installation and upgrade experience. When you deploy your application, you should replace the default experience with a custom experience that will entice users to install Silverlight and run your application. For more information on providing this experience, see the Microsoft Silverlight Installation Experience White Paper and Sample Code.

JavaScript Integration and the HTML Bridge

When you use Silverlight with JavaScript, you can keep the integration as simple as specifying JavaScript handlers for plug-in events. However, you can also establish more direct communication between your managed Silverlight code and your JavaScript code by using the HTML Bridge.

For more information, see HTML Bridge: Interaction Between HTML and Managed Code.