Silverlight 的 HtmlPage.Window.Navigate 和 HyperlinkBut​​ton 之间的区别?

发布于 2024-11-01 11:05:52 字数 1232 浏览 1 评论 0原文

我试图让我的 Silverlight 4.0 应用程序在用户单击某些内容将其带到其 Web URL 时启动关联的程序文件(文件扩展名),但无论我使用 HtmlPage.Window.Navigate 还是 HyperlinkBut​​ton,我都会有不同的体验。

我的 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 技术交流群。

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

发布评论

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

评论(2

俏︾媚 2024-11-08 11:05:53

这里有一篇简短的文章阐明了一些情况关于这个问题 - 我发现 HtmlPage.Window.Navigate 在 IE 之外根本不适合我。

但回到最初的问题,使用 dotPeek 我可以看到以下差异:

跟踪 HyperlinkBut​​ton OnClick,它将调用委托给 agcore:(XcpImports.cs)

[DllImport("agcore", EntryPoint = "NavigateToSafeURI", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static uint NavigateToSafeURINative(IntPtr context, [MarshalAs(UnmanagedType.LPWStr)] string location, [MarshalAs(UnmanagedType.LPWStr)] string target, bool checkUserInitiatedAction);

和 HtmlPage.Window.Navigate(uri) 进行此调用:

[DllImport("agcore")]
public static int DOM_Invoke(IntPtr pBrowserService, IntPtr pObject, [MarshalAs(UnmanagedType.LPWStr)] string pszMethodName, int nArgCount, [MarshalAs(UnmanagedType.LPArray)] NativeMethods.ScriptParam[] ppParams, ref NativeMethods.ScriptParam pResult, ref NativeMethods.ExceptionInfo pExcepInfo);

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)

[DllImport("agcore", EntryPoint = "NavigateToSafeURI", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static uint NavigateToSafeURINative(IntPtr context, [MarshalAs(UnmanagedType.LPWStr)] string location, [MarshalAs(UnmanagedType.LPWStr)] string target, bool checkUserInitiatedAction);

and HtmlPage.Window.Navigate(uri) makes this call:

[DllImport("agcore")]
public static int DOM_Invoke(IntPtr pBrowserService, IntPtr pObject, [MarshalAs(UnmanagedType.LPWStr)] string pszMethodName, int nArgCount, [MarshalAs(UnmanagedType.LPArray)] NativeMethods.ScriptParam[] ppParams, ref NativeMethods.ScriptParam pResult, ref NativeMethods.ExceptionInfo pExcepInfo);
纵性 2024-11-08 11:05:53

这可能是弹出窗口阻止程序问题。

您是否在任何其他浏览器中或仅使用 Uri 的 Navigate 重载中尝试过此操作?

HtmlPage.Window.Navigate(uri);

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?

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