在Index.aspx中注释掉
<param name="source" value="ClientBin/xxxxxx.xap"/>
增加如下C#代码:
<%
// 2011.11.07 修改 解决xap缓存问题
string strSourceFile = @" ClientBin/xxxxxx.xap ";
string param;
if (System.Diagnostics.Debugger.IsAttached)
param = " <param name=\"source\" value=\" " + strSourceFile + " \" /> ";
else
{
string xappath = HttpContext.Current.Server.MapPath( @"") + @" \ " + strSourceFile;
DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
param = " <param name=\"source\" value=\" " + strSourceFile + " ?ignore= "
+ xapCreationDate.ToString() + " \" /> ";
}
Response.Write(param);
%>
// 2011.11.07 修改 解决xap缓存问题
string strSourceFile = @" ClientBin/xxxxxx.xap ";
string param;
if (System.Diagnostics.Debugger.IsAttached)
param = " <param name=\"source\" value=\" " + strSourceFile + " \" /> ";
else
{
string xappath = HttpContext.Current.Server.MapPath( @"") + @" \ " + strSourceFile;
DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
param = " <param name=\"source\" value=\" " + strSourceFile + " ?ignore= "
+ xapCreationDate.ToString() + " \" /> ";
}
Response.Write(param);
%>
即可实现当xap有更新的时候立刻通过xap文件的最后修改时间来判断是否是新生成的xap,从而控制是读取缓存中的xap还是下载服务器上的xap。
参考:http://codeblog.larsholm.net/2010/02/avoid-incorrect-caching-of-silverlight-xap-file/#comment-20