Differences between Silverlight HtmlPage.Window.Navigate and HyperlinkButton?

I am trying to get a Silverlight 4.0 application to run a file extension associated with it when a user clicks something to translate it to their web URL, but I have a difference in whether I use HtmlPage.Window.Navigate or HyperlinkButton.

My web url is a RESTful url for my resource, for example. "HTTP: //.../objects/object-1/package". The URL is actually an ASP.NET MVC 2 controller that returns email content using a custom extension. That is, the headers of the HTTP response look like this:

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 hyperlink, Internet Explorer prompts me to open, save, or cancel. When I select Open, it opens the application that I linked to * .pkg:

 <HyperlinkButton TargetName="_blank" NavigateUri="http://localhost:8023/objects/object-1/package">Launch!</HyperlinkButton> 

However, if I instead use a command that ultimately 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 checked the use of Fiddler2, which in both cases the HTTP requests and the HTTP responses look the same. This seems to be either an Internet Explorer nuance or Silverlight, which I'm not sure I can overcome, but I hope the Stackoverflow community can confirm or deny this problem.

+4
source share
2 answers

Here is a short article here that shed light on this issue - I found that HtmlPage.Window.Navigate does not work for me at all outside of IE.

But returning to the original question using dotPeek, I could see the following differences:

HyperlinkButton OnClick tracking, it delegates a 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); 
+1
source

This could be a pop-up blocker problem.

Have you tried this in any other browsers or with the Navigate overload that just takes Uri?

 HtmlPage.Window.Navigate(uri); 
0
source

Source: https://habr.com/ru/post/1347975/


All Articles