Silverlight 的 HtmlPage.Window.Navigate 和 HyperlinkButton 之间的区别?
我试图让我的 Silverlight 4.0 应用程序在用户单击某些内容将其带到其 Web URL 时启动关联的程序文件(文件扩展名),但无论我使用 HtmlPage.Window.Navigate 还是 HyperlinkButton,我都会有不同的体验。
我的 Web URL 是我的资源的 RESTful URL,例如“http://.../objects/object-1/package”。该 URL 实际上是一个 ASP.NET MVC 2 控制器,它返回带有自定义扩展名的 zip 内容。也就是说,HTTP 响应标头如下所示:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 13 Apr 2011 17:22:19 GMT
X-AspNet-Version: 4.0.30319
Content-Disposition: attachment; filename=object-1.pkg
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: application/zip
Connection: Close
当我使用超链接按钮时,Internet Explorer 提示我打开、保存或取消。当我选择“打开”时,它会打开与 *.pkg 关联的应用程序:
<HyperlinkButton TargetName="_blank" NavigateUri="http://localhost:8023/objects/object-1/package">Launch!</HyperlinkButton>
但是,如果我使用最终使用 HtmlPage.Window.Navigate 的命令,IE 只会打开一个窗口,然后快速关闭:
string url = string.Format("{0}/objects/object-{1}/package", _webBaseUrl, objectId.Value);
Uri uri = new Uri(url);
HtmlPage.Window.Navigate(uri, "_blank");
我已经使用 Fiddler2 进行了验证在这两种情况下,HTTP 请求和 HTTP 响应看起来是相同的。这似乎是 Internet Explorer 或 Silverlight 的细微差别,我不确定是否可以克服,但我希望 Stackoverflow 社区能够确认或否认这个问题。
I'm trying to get my Silverlight 4.0 application to launch the associated program file a file extension when the user clicks something to take them to its web URL, but I'm having difference experiences whether I use HtmlPage.Window.Navigate or HyperlinkButton.
My web URL is a RESTful URL to my resource, e.g. "http://.../objects/object-1/package". The URL is actually an ASP.NET MVC 2 controller that returns zip content with a custom extension. That is, the HTTP response headers look like:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 13 Apr 2011 17:22:19 GMT
X-AspNet-Version: 4.0.30319
Content-Disposition: attachment; filename=object-1.pkg
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: application/zip
Connection: Close
When I use a hyperlinkbutton, Internet Explorer prompts me to Open, Save or Cancel. When I choose Open, it opens the application I have associated with *.pkg:
<HyperlinkButton TargetName="_blank" NavigateUri="http://localhost:8023/objects/object-1/package">Launch!</HyperlinkButton>
However, if I instead use a command that ultimate uses HtmlPage.Window.Navigate, IE just opens a window and then quickly closes:
string url = string.Format("{0}/objects/object-{1}/package", _webBaseUrl, objectId.Value);
Uri uri = new Uri(url);
HtmlPage.Window.Navigate(uri, "_blank");
I've verified using Fiddler2 that in both cases, the HTTP requests and HTTP responses look identical. This appears to be either an Internet Explorer or Silverlight nuance that I'm not sure I can overcome, but I hope the Stackoverflow community can confirm or deny this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一篇简短的文章阐明了一些情况关于这个问题 - 我发现
HtmlPage.Window.Navigate
在 IE 之外根本不适合我。但回到最初的问题,使用 dotPeek 我可以看到以下差异:
跟踪 HyperlinkButton OnClick,它将调用委托给 agcore:(XcpImports.cs)
和 HtmlPage.Window.Navigate(uri) 进行此调用:
There's a brief article here that shed some light on this issue - I found that
HtmlPage.Window.Navigate
didn't work for me at all outside of IE.But going back to the original question, using dotPeek I could see the following differences:
Tracking the HyperlinkButton OnClick, it delegates the call to agcore: (XcpImports.cs)
and HtmlPage.Window.Navigate(uri) makes this call:
这可能是弹出窗口阻止程序问题。
您是否在任何其他浏览器中或仅使用 Uri 的 Navigate 重载中尝试过此操作?
This might be a popup blocker issue.
Have you tried this in any other browsers or with the Navigate overload that just takes a Uri?