我正在尝试让我的Silverlight 4.0应用程序在用户点击某些内容时将相关的程序文件启动到文件扩展名以将其带到其网址,但我是否使用HtmlPage.Window.Navigate有不同的体验或HyperlinkButton。
我的网址是我资源的RESTful网址,例如“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会提示我打开,保存或取消。当我选择Open时,它会打开我与* .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社区可以确认或否认这个问题。
答案 0 :(得分:1)
有一篇简短的文章here揭示了这个问题 - 我发现HtmlPage.Window.Navigate
在IE之外根本不适用于我。
但回到最初的问题,使用dotPeek我可以看到以下差异:
跟踪HyperlinkButton 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);
答案 1 :(得分:0)
这可能是一个弹出窗口拦截器问题。
您是否曾在其他任何浏览器中尝试此操作,或者使用只需要Uri的Navigate重载?
HtmlPage.Window.Navigate(uri);