How can I solve the problem of page display failure when Silverlight is integrated into IIS?

Source: Internet
Author: User
When we use Http to create a site, the default configuration of IIS cannot display Silverlight.

The main reason is that the browser cannot download the. xap file because the default configuration of IIS does not support. xap mime-type.
You can manually download the. xap file and enter

Http: //

For example: http: // localhost/WebSample/ClientBin/SilverlightSample. xap,
I found that the "this page cannot be found" page appears and the xap file cannot be downloaded.

Solution:
1. Add. xap to the IIS mime-type configuration;
2. Rename the. xapfile as A. ZIP file;
3. Use the IHttpHandler interface to output files;

Method 1: I personally think it is a bad habit to support certain functions to modify IIS configurations. If you use a remote virtual space, it will become passive.
Method 2: It is troublesome during debugging because you need to rename the project each time you generate it.
Method 3:
First, implement IHttpHandlerusing System. IO;

/** // <Summary>
/// Summary description for SilverlightXapHandler
/// </Summary>
Public class SilverlightXapHandler: IHttpHandler
{
Public SilverlightXapHandler ()
{
}

Protected String XapFile
{
Get {return @ "ClientBin \ SilverlightSample. xap ";}
}


IHttpHandler Members # region IHttpHandler Members

Public bool IsReusable
{
Get {return true ;}
}

Public void ProcessRequest (HttpContext context)
{
// File path
String filePath = context. Request. PhysicalApplicationPath + XapFile;
FileInfo file = new FileInfo (filePath );
If (file. Exists)
{
// When the. xap file is large, do not read it into the memory at one time
Byte [] buf = new byte;
Using (FileStream fs = file. OpenRead ())
{
Fs. Read (buf, 0, buf. Length );
}
Context. Response. AddHeader ("Content-Disposition", "attachment; filename = SilverlightSample. xap ");
Context. Response. BinaryWrite (buf );
}
Else
{
// No file found
Context. Response. Status = "404 Not Found ";
}

}

# Endregion
}

Add the <Add verb = "*" path = "ClientBin/SilverlightSample. aspx" type = "SilverlightXapHandler"/>

Modify Silverlight display page connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.