Question

for my IIS7 website, i've had to go into the IIS7 Services Manager and define all the bindings for the site. Works fine.

I was wondering if it's possible to do this programatically in the web.config file instead? I know you can provide a few iis7 settings in there.. wasn't sure if it's possible to also include the bindings?

eg.

  1. http; all unassigned ip's; port 80; foo.domain.com
  2. https; 192.168.0.2; port 443; blah.domain.com
Was it helpful?

Solution

The configuration is found in the config file of the parent applicationHost.config, however I'm not sure it can be overridden. For example in IIS Express the section you are looking for is:

<system.applicationHost>
...

    <sites>
        <site name="Development Web Site" id="1" serverAutoStart="true">
            <application path="/">
                <virtualDirectory path="/" physicalPath="%IIS_BIN%\AppServer\empty_wwwroot" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation=":8080:localhost" />
            </bindings>
        </site>
        <siteDefaults>
            <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
            <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
        </siteDefaults>
        <applicationDefaults applicationPool="IISExpressAppPool" />
        <virtualDirectoryDefaults allowSubDirConfig="true" />
    </sites>

</system.applicationHost>

You could try running (sorry - I haven't tried any of these myself):

%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.applicationHost

But from a security point of view it doesn't make sense to allow web.configs to each individually mess with system.applicationHost, as one site's config could break every other site.

OTHER TIPS

Look at the Microsoft.Web.Administration namespace. you can then configure and maniuplate most of IIS 7 from C# code.

there is also a utility Appcmd that allows you to manipulate almost everything in IIS 7.0. be warned that this tool has tons of options and switches. I have only used it for the most basic of tasks such as changing physical directories on applications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top