Programmatically starting an HTTP server in C#?

前端 未结 4 844
不思量自难忘°
不思量自难忘° 2021-02-01 11:20

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 si

4条回答
  •  走了就别回头了
    2021-02-01 11:54

    You can use the 'net' command to start or stop services, including the service used by IIS (the web server on windows).

    Make sure IIS is installed and your site works like a normal ASP.Net site. Then set the "World Wide Web Publishing" service startup type to manual instead of Automatic. Now you can start it at any time by issuing a command like this at the console (and from your program via Process.Start()):

    net start w3svc

    Now you'll have some issues with this if you're thinking more about just dumping this app on any old computer. But if the app is intended to help manage a specific system you'll be fine.

提交回复
热议问题