Silverlight 5 - 使用反缓存技巧时 OOB 安装/更新损坏

发布于 2024-12-28 07:23:49 字数 2795 浏览 2 评论 0原文

我在 Silverlight 上使用了时间戳技巧。 (请参阅 GetLastWriteTime() 使用 如何强制 Firefox 不缓存或重新下载 Silverlight XAP 文件?)成功地使用 Silverlight 4。使用 Silverlight

5运行时*,OOB 安装/自动更新功能现在似乎已损坏。我有两个问题:

  • 在浏览器中启动时,当前安装状态始终为“未安装”(代码中: Application.Current.InstallState == System.Windows.InstallState.NotInstalled 始终为 true
  • 在 OOB 模式下启动时,总​​是说有新版本可用(在代码中:CheckAndDownloadUpdateAsync() 总是返回 e.Error == nulle.UpdateAvailable == true)。

有其他人遇到过这种情况吗?更好的是,有解决方法吗?


* 精度: 目前,我的应用程序是使用 Silverlight 5 工具构建的,但目标是 Silverlight 4,并且在 Silverlight 4 开发人员运行时上运行良好。该问题发生在(至少)我使用 Silverlight 5 Developer Runtime 的开发计算机上。


更新:我已经用 Fiddler 检查了我的开发盒上发生的情况。调用更新过程时,我看到:

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

这对我来说很好,除了服务器(服务器:ASP.NET Development Server/10.0.0.0,X-AspNet-Version:4.0.30319)返回新版本,其中包含以下内容缓存标头:

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

每次运行应用程序时,检查请求都有正确的日期(服务器之前返回的日期),并且每次,服务器都会说它有一个新版本,并带有当前日期。我将尝试调整服务器配置。

更新2:我的Web.config文件中有一个缓存控制指令,但删除它只解决了一半的问题。现在,浏览器内应用程序检测到 OOB 安装正常,但更新周期继续,并具有相同的 Fiddler 跟踪。

Update3:问题肯定与调试网络服务器有关。使用相同的 Web.config 部署到正确的 IIS 的同一应用程序不会出现此问题。但这仍然很烦人,因为它大大减慢了我的 OOB 调试过程。

Update4: 事实上,即使在我的主 IIS 部署上,问题仍然存在,并且在其他服务器上也发生过也是(并使用 PHP 来生成时间戳而不是 ASP.NET)。因此,我们将不胜感激任何帮助。

Update5:根据要求,这是我的代码,相当简单:

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是一个枚举类型属性,允许我在其他地方选择正确的本地化字符串。

Update6: 各个//(...) 部分正在(间接)更改应用程序的视图,而UpdateType 则不会。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁我热情 2025-01-04 07:23:49

我怀疑这与内置的 Cassini / Visual Studio 开发服务器和 SL5 由于某种原因不能很好地协同工作有关。

我还使用了您提到的反缓存技巧,并且我遇到了 Application.Current.InstallState 始终报告 NotInstalled 以及 CheckAndDownloadUpdateAsync( ) 始终报告e.UpdateAvailable = true

因此,我更改了 Web 项目配置以使用 IIS Express 而不是内置的 Visual Studio 开发服务器,并将 Silverlight 应用程序重新安装到桌面。最后,一切开始按预期进行。为了使 Application.Current.InstallState = InstalledCheckAndDownloadUpdateAsync() 报告 e.UpdatedAvailable = false

更新

抱歉,没有发现您在实时 IIS 部署中也遇到了这种情况。

更新 2

我的反缓存 HTML 按要求:

<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>

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>
半窗疏影 2025-01-04 07:23:49

从 Visual Studio 作为 OOB 运行时,我遇到了同样的问题

关于从 IIS 远程运行,我注意到我必须编辑添加到 web.config 的缓存策略 - 保留该策略将始终显示更新/下载进度徽标(但会下载速度比新版本可用时要快,可能只下载了部分,但是每次看到下载进度都会很烦人)

我不得不删除(注释掉)尝试缓存 .xap 直到更改的部分

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

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>
凉栀 2025-01-04 07:23:49

我建议不要使用 DateTime 方法。
相反,请将版本号附加到 xap url。

编辑
抱歉,刚刚注意到您正在使用 LastWriteTime,这应该没问题。

当 xap 通过 IIS 提供服务时,尝试使用 fiddler 查看网络流量。

另外,请向我们展示您执行 OOB 安装检查的代码。

编辑2

UpdateType的默认值是多少?也许检查 UpdateType 值的代码可能在调用 CheckAndDownloadUpdateCompleted 之前运行。

对于Application.Current.InstallState,挂钩事件App.Current.InstallStateChanged。
我想也许 Application.Current.InstallState 的默认值是 System.Windows.InstallState.NotInstalled 直到 silverlight 运行时完成检查安装状态,在这种情况下它会触发 InstallStateChanged 事件。

当您的页面在网络浏览器中加载时,检查其 html 源代码,也许上次文件写入时间被意外更新。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文