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