How to create a simple Browser Enabled WPF application
I am writing a series of posts about WPF Browser Application, XBAP and configuration tips. I’m going to host this application in IIS 5.1 and I developed them in .Net 3.5. The reason I have chosen IIS5.1 and .Net 3.5 is because of challenges I had in one of my recent projects. Configuring this type of projects is different in other versions of IIS and .Net frameworks and they are not is subject of this post series.
- How to create a simple Browser Enables WPF application
- How to host a windows form application inside XBAP
- How to sign the XBAP with your own certificate
Firstly run Visual Studio 2010 and select new project from file menu
To create simple WPF browser application you need to select “WPF Browser Application” template from project templates. Once project template is created open Page1.xaml Xaml code and change Grid into following code
<Grid> <Rectangle Fill="#33CC66" Width="2in" Height="1in" Canvas.Top="25" Canvas.Left="50" StrokeThickness="6px" Stroke="Orange" /> </Grid>
This Xaml code will create a simple rectangle with border and if you run this application, It will show following shape inside your browser.
Deploying a WPF application
There are multiple ways to do that. Simply you can publish your application using visual studio. Right-click on project and select publish menu. Publish wizard is displayed. Follow the steps until the end of publish steps.
You must follow Microsoft instruction for How to: Configure IIS 5.0 and IIS 6.0 to Deploy WPF Applications to configure your server and client requires Internet Explorer plus .Net Framework to run this application.
Basically internet application which runs inside the browsers should have restricted access to critical resources. It means WPF browser application -By default- should respect to these restrictions so that client can make sure there is no harm to execute this application. Browser Enabled application by default is marked as partially trusted and ClickOnce security setting is set to Internet Zone so that your application will be running on the client browser without any problem.
As you see “Enable ClickOnce security settings” and “This is a partial trust application” are ticked by default and and ClickOnce manifests is signed by a temporary key. Which means on one your application will be restricted to security permission which is fully described in this document. On the other hand your application will be executed on client browser without any other additional configuration.
Above picture shows that you can run This simple WPF Browser Enabled application in “Internet Zone”.
The main reason of writing this post series for me is hosting windows form application inside XBAP application and running inside browser. In next post we will see how to host an existing windows form application within a WPF Browser application.
Sample project is also available you can download it here