Displaying an IIS hosted site in CEFSharp

Full article

A few weeks ago I shared how you can use CEFSharp to display an html page. I called it hosting, but uh, it was really just displaying a single html page that was baked into the project itself. Yeah, cutting edge, I know. It's WinForms, the bar is low folks.

Hosting a simple webpage in WinForms with CEFSharp
WinForms and the web. Like oil and water, they don’t mix well. But with CEFSharp, they mix a LOT better. Let’s check it out.

This time we'll host the same page in IIS and see how CEFSharp can still interact with it. I won't give a whole overview of IIS, but if you want to try it yourself, here's a few steps. Enable IIS in Windows Features, if it's not already.

Copy the BasicCefSharp_Site folder from my sample code into the c:\inetpub\wwwroot directory. Reusing that location will make your life easier, since there's some security on the wwwroot folder that you won't have to recreate.

In IIS, right-click sites and add a new website. Nothing matters in here, other than pointing to the correct location on disk, and changing the port if you don't want to interrupt something else already running locally on the default port 80.

Open the new website in your browser and you should see the sample page in all its amazing hypertext markup glory.

Fire up the WinForms project, and give it a go. You'll need to change line 27 if you picked a different port. Otherwise, it behaves like it did last time, except now you're interacting with an actual website running locally, and not just a one-off html page.

I couldn't help monkeying with it a little bit though, adding an address bar that subscribes to the CEFSharp control's AddressChanged event handler to display the current URL. Oh, and it now has twice as many hypertextual markedup pages! Check it out on GitHub.

Author

Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.


Comments / Reactions

One of the most enjoyable things about blogging is engaging with and learning from others. Leave a comment below with your questions, comments, or ideas. Let's start a conversation!