I'm creating a Silverlight application that is using <Button>
tags, and calling HtmlPage.Window.Navigate(new Uri("http://www.google.com"));开发者_JAVA百科
during the Click
event.
In debug, this works fine. I can click the button and be redirected to the requested location. When publishing this to the server, the requested action fails to execute.
I've also tried other variations, such as calling JavaScript via HtmlPage.Window.Invoke()
or just a simple refresh of the page by using HtmlPage.Document.Submit()
, but both fail to work once pushed to the server.
I'm stumped at this point. The only real difference between the two locations the file is run are:
- The Silverlight application is wrapped in a MVC page instead of an auto-generated test page
- It's also sitting on a different port of the server -- one I set aside for my .NET 4 testing. The MVC page is on :80, and the Silverlight app is on :81
It almost seems like anytime the Silverlight application tries to interact with the MVC page on a JavaScript level, it fails (and, of course, throws no visible error). The reason I'm considering it to be that is because, while I was writing this, I tried to pop up a message box via the MessageBox.Show()
command in Silverlight -- it did not appear.
Any other ideas I can try?
The fact that the XAP in on port 81 and your JavaScript is on port 80 makes this a cross-domain call. By default Silverlight will not allow cross-domain JavaScript interaction.
Take a look at the security settings for this kind of scenarios.
I think that in your case, it will be necessary to enable cross-domain HTML access using enableHtmlAccess, like this:
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2,"
type="application/x-silverlight-2"
width="300" height="100">
<param name="source"
value="http://www.northwindtraders.com/MySample.xap"/>
<param name="enableHtmlAccess" value="true" />
</object>
</div>
精彩评论