IE security message when source of browser control is set to a local resource in wpf
- I am using the web browser control to play a .swf file in a wpf app. To do this, I set the .swf file as the source of the web browser control.
However, when I run the application, I get an IE security message when the source is a local .swf file. How can I suppress this IE sucurity message?
[P.S: the settings of my web browser doesn't appear to affect this at all]
Answers
- Hi,
When the swf file is loaded from local machine, it can be blocked by the Local Machine Lockdown feature.
There're many ways to suppress this security message.
1. Create a HTML page and add a mark-of-web at the beginning of the HTML page.
<!-- saved from url=(0014)about:internet -->
<HTML>
<BODY>
<object width="550" height="400">
<param name="movie" value="1.swf">
<embed src="1.swf" width="550" height="400">
</embed>
</object>
</BODY>
</HTML>
Then navigate to this HTML page instead of the swf file.
For more information about the mark-of-web, see:
http://msdn.microsoft.com/en-us/library/ms537628(VS.85).aspx
2. Use the Windows Forms WebBrowser control instead.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="Window1" Height="332" Width="441">
<Grid>
<WindowsFormsHost Margin="10,15,32,23" Name="windowsFormsHost1" >
<mf:WebBrowser x:Name="webBrowser1"/>
</WindowsFormsHost>
</Grid>
</Window>
void Window1_Loaded(object sender, RoutedEventArgs e)
{
webBrowser1.Navigate(@"c:\test\1.swf");
}
3. Create a share folder on your local machine, and put the swf file in it, then navigate to the swf file in this way:
webBrowser1.Navigate(new Uri(@"file://127.0.0.1/YourShareFolder/1.swf "));
If anything is unclear, please feel free to let me know.
Have a nice day.
Best Regards,
Zhi-Xin
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!- Marked As Answer byZhi-Xin YeMSFT, ModeratorTuesday, November 10, 2009 1:53 PM
All Replies
- Hi,
When the swf file is loaded from local machine, it can be blocked by the Local Machine Lockdown feature.
There're many ways to suppress this security message.
1. Create a HTML page and add a mark-of-web at the beginning of the HTML page.
<!-- saved from url=(0014)about:internet -->
<HTML>
<BODY>
<object width="550" height="400">
<param name="movie" value="1.swf">
<embed src="1.swf" width="550" height="400">
</embed>
</object>
</BODY>
</HTML>
Then navigate to this HTML page instead of the swf file.
For more information about the mark-of-web, see:
http://msdn.microsoft.com/en-us/library/ms537628(VS.85).aspx
2. Use the Windows Forms WebBrowser control instead.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="Window1" Height="332" Width="441">
<Grid>
<WindowsFormsHost Margin="10,15,32,23" Name="windowsFormsHost1" >
<mf:WebBrowser x:Name="webBrowser1"/>
</WindowsFormsHost>
</Grid>
</Window>
void Window1_Loaded(object sender, RoutedEventArgs e)
{
webBrowser1.Navigate(@"c:\test\1.swf");
}
3. Create a share folder on your local machine, and put the swf file in it, then navigate to the swf file in this way:
webBrowser1.Navigate(new Uri(@"file://127.0.0.1/YourShareFolder/1.swf "));
If anything is unclear, please feel free to let me know.
Have a nice day.
Best Regards,
Zhi-Xin
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!- Marked As Answer byZhi-Xin YeMSFT, ModeratorTuesday, November 10, 2009 1:53 PM
- Or in order to bypass the page creation use NavigateToString(finalHtml); method from WebBrowser.
String jsString = "<script type=\"text/javascript\" language=\"JavaScript\"> window.onerror=myErrorHandler; function myErrorHandler() { return true;}</script>" ;String finalHtml = String .Format("<html><head>{1}</head><body style=\"background-color:#F1F1F1; margin:0; padding:0\"><object width=\"100%\" height=\"100%\"><param name=\"movie\" value=\"{0}&hl=fr&fs=1&rel=0&border=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"><param name=\"wmode\" value=\"transparent\"></param><embed src=\"{0}&hl=fr&fs=1&rel=0&border=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" wmode=\"transparent\" allowfullscreen=\"true\" width=\"100%\" height=\"100%\"></embed></object></body></html>" , YourMediaUrl, jsString);
And so call yourWebBrowser.NavigateToString(finalHtml);
I use this in a project that display Youtube, Dailymotion, Wat.tv in wpf app (work in IE8 too !)
Try with put this link http://www.youtube.com/v/77TfYaEjZtU in YourMediaUrl
http://slouge.wordpress.com - Thanks all:
Zhi-Xin Ye: I tried the 2nd method you suggest but still get the same message I'm afraid; the browser is in a user-control and is now wrapped in a WindowsFormsHost as you suggest. Do you know what I am doing wrong?
UserControl
x:Class="cntrlHome"
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="705"
xmlns:mf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
.
.
.
<Border Grid.Column="1" Margin="5.555,12,12,31.108" Name="Border1" Grid.RowSpan="2" CornerRadius="4,4,4,4">
<WindowsFormsHost Grid.Column="1" Grid.RowSpan="2" Margin="2">
<mf:WebBrowser x:Name="webBrowserHome" />
</WindowsFormsHost>
</Border>


