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
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".
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
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.
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.
Read this Creating Sites and Virtual Directories in IIS and this Using IIS Programmatic Administration i hope this will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With