Displaying an IIS hosted site in CEFSharp

Thanks to CEFSharp, we can finally bring WinForms to the web! That didn't sound right. Okay, let's just look at hosting a site in IIS and showing it.

Displaying an IIS hosted site in CEFSharp
Photo by Med Badr Chemmaoui / Unsplash

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.