Silverlight 5 - OOB install/update broken when using anti-cache trick

泪湿孤枕 提交于 2019-12-18 08:57:43

问题


I was using the timestamp trick on the Silverlight <object> (see GetLastWriteTime() using answers in How do you force Firefox to not cache or re-download a Silverlight XAP file?) successfully with Silverlight 4.

Using a Silverlight 5 runtime*, the OOB install/auto-update feature now seems broken. I have two issues:

  • when launching in browser, the current install state is always 'not installed' (in code: Application.Current.InstallState == System.Windows.InstallState.NotInstalled is always true)
  • when launching in OOB mode, it's always saying that a new version is available (in code: CheckAndDownloadUpdateAsync() always returns with e.Error == null and e.UpdateAvailable == true).

Has anyone else encountered this, and better yet, has a workaround?


* Precision: currently my app is built using the Silverlight 5 Tools, but is targeting Silverlight 4, and works fine on a Silverlight 4 Developer Runtime. The problem occurs on (at least) my dev machine using the Silverlight 5 Developer Runtime.


Update: I've checked with Fiddler what happens on my dev box. When the update process is invoked, I see:

GET /ClientBin/Client.xap?timestamp=23%2f01%2f2012+17%3a42%3a14 HTTP/1.1
If-Modified-Since: Tue, 24 Jan 2012 09:10:07 GMT

That's fine for me, except that the server (Server: ASP.NET Development Server/10.0.0.0, X-AspNet-Version: 4.0.30319) returns a new version, with the following cache headers:

HTTP/1.1 200 OK
Cache-Control: private
Date: Tue, 24 Jan 2012 09:11:28 GMT

Each time I run the app, the check request has the right date (the one previously returned by the server), and each time, the server says it has a new version, with the current date. I will try to tweak the server config.

Update2: I had a cache control directive in my Web.config file, but removing it only solved half the problem. Now the in browser app detects that the OOB install is ok, but the update cycle continues, with the same Fiddler trace.

Update3: The problem is definitely related to the debug web server. The same application deployed to a proper IIS with the same Web.config doesn't have this issue. But this is still annoying, as it considerably slows down my OOB debug process.

Update4: In fact, the problem is still present even on my main IIS deployment, and has happened on other servers too (and using PHP to generate the timestamp instead of ASP.NET). So any help is appreciated.

Update5: As requested, here is my code, fairly straightforward:

private void CheckAndDownloadUpdateCompleted(object sender, System.Windows.CheckAndDownloadUpdateCompletedEventArgs e)
{
    if (e.Error != null)
    {
        if (e.Error is PlatformNotSupportedException)
        {
            UpdateType = UpdateTypes.PlatformUpdate;
            //(...)
            return;
        }
        else if (e.Error is SecurityException)
        {
            UpdateType = UpdateTypes.ElevationRequired;
            //(...)
            return;
        }
        else
        {
            // Error handling code
            //(...)
        }
    }
    else if (e.UpdateAvailable)
    {
        UpdateType = UpdateTypes.Available;
        //(...)
        return;
    }

    UpdateType = UpdateTypes.NoUpdate;

    //(...)
}

UpdateType is an enum type property that allow me to pick the right localized string somewhere else.

Update6: The various //(...) parts are (indirectly) changing the view of the application, UpdateType is not.


回答1:


I suspect this has something to do with the builtin Cassini / Visual Studio Development server and SL5 not playing nicely together for some reason.

I'm also using the anti-cache trick you mentioned and I was experiencing the same behavior of Application.Current.InstallState always reporting NotInstalled as well as CheckAndDownloadUpdateAsync() always reporting e.UpdateAvailable = true.

So I changed my web project configuration to use IIS Express instead of the the builtin Visual Studio Development server and re-installed the Silverlight app to the desktop. Finally, everything started working as expected. In order words Application.Current.InstallState = Installed and CheckAndDownloadUpdateAsync() is reporting e.UpdatedAvailable = false.

Update:

Sorry, didn't see that you're experiencing this as well on live IIS deployments.

Update 2:

My anti-cache HTML as requested:

<div id="silverlightControlHost" align="center" style="height:100%">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight2" width="100%" height="100%">
      <%
          string source = @"~/ClientBin/EskomVDT.SL.xap";
          string param;

          if(System.Diagnostics.Debugger.IsAttached) {
              param = "<param name=\"source\" value=\"" + VirtualPathUtility.ToAbsolute(source) + "\" />";                                   
          }
          else {
              string xapPath = HttpContext.Current.Server.MapPath(source);
              DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xapPath);

              param = "<param name=\"source\" value=\"" + VirtualPathUtility.ToAbsolute(source) + "?ignore=" + xapCreationDate.ToString("yyyy-MM-dd-hh-mm-ss") + "\" />";
          }

          Response.Write(param);
      %>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="5.0.61118.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>      </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
</div>



回答2:


I have the same issue when run as OOB from Visual Studio

Regarding running from IIS remotely, I noticed that I had to edit the caching policy I had added to web.config - keeping that would always show the update/download progress logo (but would download faster than when a new version was available, only partial download maybe, but annoying to see the download progress even for a while every time)

I had to remove (comment out) the part that was trying to cache .xap till changed

<caching>
  <profiles>
    <add extension=".xap" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
  </profiles>
</caching>



回答3:


I recommend not using the DateTime approach.
Instead, append the version number to the xap url.

Edit
Sorry, just noticed you're using the LastWriteTime, which should be fine.

Try using fiddler to view the network traffic when the xap is served through IIS.

Also, show us your code that does the OOB installed check.

Edit 2

What is the default value of UpdateType? Maybe the code that checks the value of UpdateType might have run before CheckAndDownloadUpdateCompleted is called.

In regards to Application.Current.InstallState, hook into the event App.Current.InstallStateChanged.
I'm thinking maybe the default value of Application.Current.InstallState is System.Windows.InstallState.NotInstalled until the silverlight runtime has finished checking the install state, at which case it then fires the InstallStateChanged event.

When your page is loaded in your web browser, check its html source, maybe the last file write time is getting updated unexpectedly.



来源:https://stackoverflow.com/questions/8974957/silverlight-5-oob-install-update-broken-when-using-anti-cache-trick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!