Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting URL hash from Silverlight sometimes failing

In our silverlight application we set the location hash property of the browser window to bookmark the current control and query parameters being requested. This is done through javascript via Silverlight like so:

var hashCode = "Example.ControlNamespace.ClassName?clientID=62189";
HtmlPage.Window.Eval(string.Format("window.location.hash='{0}'", hashCode));

This works well enough, but we get intermittent errors from production where this is failing with a stack track that ends at that line..

System.InvalidOperationException: Eval failed. at System.Windows.Browser.HtmlWindow.Eval(String code)

This only happens occasionally, but I would like to know what is causing it. I've been able to replicate it once myself using IE8, so I don't think there are any obscure browsers causing this. It seems that it is sometimes invalid to set the hash, but I don't know why. Also if it matters its hosted on a secure connection, https.

Thanks in advance.

Edit: I was able to replicate it again. When debugging the javascript the error was 'permission denied'. This seems to only happen on the first load of the page, so maybe the page isn't finished loading and the url hash is not allowed to be changed until it is complete?

like image 955
Jace Rhea Avatar asked Oct 10 '22 09:10

Jace Rhea


1 Answers

This may be associated with this particular issue here:

Suppress navigation when setting HtmlPage.Window.CurrentBookmark property in Silverlight.

The behavior I've seen is that when you set the hash in IE after a redirect, the page refreshes (rather than giving you an "permission denied"), but perhaps there are other scenarios when you're not allowed to do so, e.g., if you're running under HTTPS.

If it does turn out that this is the problem, the only real workaround I've seen is to detect if you're in that scenario (i.e., you've reached this page after a redirect, and you're running in IE), and refresh the page (using JavaScript) before you load your Silverlight application.

like image 87
Ken Smith Avatar answered Oct 16 '22 22:10

Ken Smith