I’m a C#, ASP.NET newbie.
Let’s say I have an existing C# project (from a “Console Application” template; I work with Visual Studio). I want to be able to start a simple HTTP server and serve .aspx pages (or ordinary text even, in which case I’m also looking for a nice templating library ^^), but only if a certain command is given to the program via the command-line interface. (So, the server is not up by default.)
How could I best accomplish this?
Thank you very much for any help!
Edit: To clarify, I’d like all of this functionality to be embedded in a single non-webapp non-website project. That is, the project is made up of three parts: the command-line interface, the optionally-run web interface (the HTTP server), and the core that waits for and reacts to requests by either of those two interfaces. This is the current state of the existing project, sans the web-interface.
You could host the ASP.NET runtime inside a console application. Here’s an example:
You might get a
TypeLoadExceptionwhen you run this program. You have to create abinsubdirectory to your current directory and move a copy of the executable to it. This is because the ASP.NET runtime will look for a bin subdirectory. Another option is to putSimpleHostinto a separate assembly which you deploy into the GAC.