How to run IIS Express as a process started via a Windows Service

后端 未结 6 1065
情歌与酒
情歌与酒 2020-12-05 15:41

I am trying to distribute IIS Express with my application. IIS Express will serve external web requests on port 80.

I have no problems running IIS Express as well as

6条回答
  •  借酒劲吻你
    2020-12-05 16:36

    The answer like: string IIS_EXPRESS = @"C:\Program Files\IIS Express\iisexpress.exe";

        StringBuilder arguments = new StringBuilder();
        arguments.Append(@"/path:");
        arguments.Append(@"C:\Inetpub\wwwroot\ClientSyncService");
        arguments.Append(@" /Port:2000");
        Process process = Process.Start(new ProcessStartInfo()
            {
                FileName = IIS_EXPRESS,
                Arguments = arguments.ToString(),
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            });
    

    Should work, however the trick is that you need to grant ACLs for the the identity of the service so that it can take ownership of port 80. In other words, during your setup program (assuming you have an MSI that will run elevated), make it run a command line like: netsh http add urlacl url=http://WhateverMachineName:80/ user=everyone

    where you can limit "everyone" to instead just a specific account under which your service will be running. When you do that, then IIS express should be able to start just fine without requiring administrator privileges.

提交回复
热议问题