Like most projects Program After delivery, we will modify the xap file based on the customer's requirements and send it to the customer. After testing, the customer will deploy the file in the production environment.
In this way, we often face a problem. The customer does not see any changes after updating the xap, even because the changes to the relevant files such as the WCF Service will cause exceptions in program execution. This is obvious because our xap file is cached. When the new xap file is replaced on the server, it is not downloaded from the server again. At this time, we certainly need to tell the customer how to clean up the cache and so on, and then encounter a computer blind (in most cases) is even more miserable. The customer complained that the project manager was dumb to eat Huanglian...
Is there any way to solve the problem mentioned above? Of course, listen to the decomposition.
Let's take a look at the code for checking in the Silverlight application in HTML.CodeExample
< Object Data = "Data: Application/x-silverlight-2 ," Type = "Application/x-silverlight-2" Width = "100%" Height = "100%"> < Param Name = "Source" Value = "Clientbin/mefsample. xap"/> < Param Name = "Onerror" Value = "Onsilverlighterror"/> < Param Name = "Background" Value = "White"/> < Param Name = "Minruntimeversion" Value = "4.0.50826.0"/> < Param Name = "Autoupgrade" Value = "True"/> < A Href = "Http://go.microsoft.com/fwlink? Linkid = 149156 & V = 4.0.50826.0" Style =" Text-Decoration : None "> < IMG SRC = "Http://go.microsoft.com/fwlink? Linkid = 161376" ALT = "Get Microsoft Silverlight" Style =" Border-style : None "/> </ A > </ Object >
Pay attention to the following line, and we will start from here.
<ParamName= "Source"Value= "Clientbin/mefsample. xap"/>
We know that to prevent the browser from automatically caching files, a common practice is to add a random string (such as a verification code refresh) after the file name to be loaded, such as guid and datetime. now. ticks.
Therefore, the idea here is to determine whether to re-load the xap package by judging the xap file generation time.
The code for the final view is as follows:
< Object Data = "Data: Application/x-silverlight-2 ," Type = "Application/x-silverlight-2" Width = "100%" Height = "100%"> @{ String Xapfile = "Clientbin/mefsample. xap" ; String Xappath = Httpcontext . Current. server. mappath ( "\\" ) + Xapfile; Datetime Xapcreateddate = system. Io. File . Getlastwritetime (xappath); xapfile + = "? V =" + Xapcreateddate; } < Param Name = "Source" Value =" @ Xapfile "/> < Param Name = "Onerror" Value = "Onsilverlighterror"/> < Param Name = "Background" Value = "White"/> < Param Name = "Minruntimeversion" Value = "4.0.50826.0"/> < Param Name = "Autoupgrade" Value = "True"/> < A Href = "Http://go.microsoft.com/fwlink? Linkid = 149156 & V = 4.0.50826.0" Style =" Text-Decoration : None "> < IMG SRC = "Http://go.microsoft.com/fwlink? Linkid = 161376" ALT = "Get Microsoft Silverlight" Style =" Border-style : None "/> </ A > </ Object >
Note: Here I use ASP. NET MVC (razor syntax) to host xap, which is also applicable to webform or webform view. Please change it on your own.