Cipher
Cipher

Reputation: 6102

Configuring IIS on the user's machine through code C#

I configured a website to run locally on IIS for use on my machine. My desktop application has something use with this locally running website for some operations.

There are the steps I followed to configure the website

  1. Use IIS Manager to configure a web application pointed at a directory. (C:\somefolder):
    Start > Internet Information Services (IIS) Manager.
    Expand the left-hand tree view and right-click on "Default Web Site".
    Select "Add Application".
    Set the "Alias" to "sampleweb"
    Click the "Select" button and choose the "ASP.NET 4.0" application pool.
    Set the "Physical path" to the directory - C:\somefolder.
    Click "OK".

  2. Use IIS Manager to configure a virtual directory pointed at another directory (C:\somefiles).
    Start > Internet Information Services (IIS) Manager.
    Expand the left-hand tree view and right-click on "Default Web Site".
    Select "Add Virtual Directory".
    Set the "Alias" to "somefiles".
    Set the "Physical path" to the directory - C:\somefiles.
    Click "OK".

So, when I distribute the application, I want to be able to set up a local server on the user's machine, and perform the above stesp in IIS.
I have been able to do the setting up of local server part, but I am confused with on how to perform the above stesp programmatically on the user's machine to get the website running.
Any suggestions? I'm on Windows 7 64 bit IIS7

Upvotes: 10

Views: 6858

Answers (2)

Likurg
Likurg

Reputation: 2760

Read this Creating Sites and Virtual Directories in IIS and this Using IIS Programmatic Administration i hope this will help

Upvotes: 4

Oded
Oded

Reputation: 499362

Take a look at the Microsoft.Web.Administration namespace - it contains managed classes to manage all aspects of IIS, including the configuration you are talking about.

The Microsoft.Web.Administration namespace contains classes that a developer can use to administer IIS Manager. With the classes in this namespace, an administrator can read and write configuration information to ApplicationHost.config, Web.config, and Administration.config files.

You can use these classes in your C# code or from PowerShell.

Upvotes: 9

Related Questions