I have a desktop written with Winforms. Now I have requests that people want to access the data from other machines. First I thought about a regular Client/Server app but now I think best would be if the app could act as HTTP server and send HTML to connected browsers.
Does anybody know if there is a library available to add HTTP server functionality to an app? Ideally it would be able to serve ASP.NET content.
To host ASP.NET content (such as .aspx pages) from your own application (without IIS), use the classes in the System.Web.Hosting namespace.
The canonical example usage of this is the standalone testing web server that comes with Visual Studio (based on "Cassini"). Source code for "Cassini" it is available here: http://blogs.msdn.com/dmitryr/archive/2008/10/03/cassini-for-framework-3-5.aspx
Here is a (somewhat dated) MSDN article on the subject: http://msdn.microsoft.com/en-us/magazine/cc188791.aspx
Expecting your server to be as robust as IIS is a long shot. So be sure to carefully evaluate your needs and manage your expectations :)
As Jon has said, you can use HttpListener to implement a HTTP server. For serving ASP.NET content, see the System.Web.Hosting namespace.
One thing to be aware of with your design is that your HTTP server will be available only while the app is running. So when the user of the desktop app closes it or logs off, other people will no longer be able to access the data via your Web interface. You may therefore want to reconsider your approach and instead factor out the data access functionality into a separate DLL that you can then call from an IIS-hosted ASP.NET app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With