Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

iis

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

like image 604
Cipher Avatar asked Apr 12 '12 08:04

Cipher


People also ask

How do I deploy a website using IIS?

In IIS, right-click the Default Web Site, choose Deploy > Configure Web Deploy Publishing. If you don't see the Deploy menu, see the preceding section to verify that Web Deploy is running. In the Configure Web Deploy Publishing dialog box, examine the settings. Click Setup.


Video Answer


2 Answers

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.

like image 162
Oded Avatar answered Oct 09 '22 21:10

Oded


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

like image 30
Likurg Avatar answered Oct 09 '22 20:10

Likurg