Sign in
CarlosAg Blog
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
Atom
RSS for comments
Search
Tags
.NET
ARR
ASP.NET
IIS
IIS Manager
IIS News Item
Microsoft.Web.Administration
Personal
SEO
URL Rewrite
Windows Azure
WinForms
Archive
Archives
July 2012
(1)
March 2012
(1)
December 2011
(1)
August 2011
(3)
January 2011
(1)
November 2010
(1)
October 2010
(1)
May 2010
(2)
April 2010
(3)
March 2010
(1)
February 2010
(2)
November 2009
(9)
October 2009
(1)
September 2009
(1)
July 2009
(1)
June 2009
(6)
February 2009
(1)
November 2008
(2)
October 2008
(1)
September 2008
(4)
August 2008
(3)
July 2008
(5)
June 2008
(4)
May 2008
(3)
April 2008
(4)
March 2008
(6)
February 2008
(1)
January 2008
(2)
December 2007
(1)
November 2007
(2)
October 2007
(1)
September 2007
(2)
June 2007
(1)
May 2007
(1)
March 2007
(2)
February 2007
(1)
August 2006
(1)
June 2006
(1)
May 2006
(1)
April 2006
(2)
November 2005
(1)
September 2005
(1)
August 2005
(1)
July 2005
(1)
Microsoft.Web.Administration in IIS 7
MSDN Blogs
>
CarlosAg Blog
>
Microsoft.Web.Administration in IIS 7
Microsoft.Web.Administration in IIS 7
CarlosAg
17 Apr 2006 1:56 AM
Comments
56
While creating the new administration stack in
IIS 7
, we were looking into the different ways users could manipulate the server configuration as well as the new runtime information available in IIS 7 (Internally we call this RSCA-Runtime State and Control API) from managed code, and we realized we needed to provide a simpler and more straight forward API that developers could consume from managed code. Microsoft.Web.Administration is the answer to this problem. This API is designed to be simple to code against in an “intellisense-driven” sort of way. At the root level a class called ServerManager exposes all the functionality you will need.
To show the power and simplicity of this API, let’s look at some samples below. To try this samples just create a new Console Application in Visual Studio and add a reference to Microsoft.Web.Administration.dll that can be found at IIS directory (%WinDir%\System32\InetSrv).
Please note that the following code is based on Windows Vista Beta 2 code and will likely change for the release candidate versions of Windows Vista since we have planned several enhancements to simplify the API and expose more features into it.
The following picture shows the main objects (excluding Configuration related classes).
Creating a Site
ServerManager iisManager
= new
ServerManager()
;
iisManager.Sites.Add(
"NewSite"
,
"http"
,
"*:8080:"
,
"d:\\MySite"
)
;
iisManager.Update()
;
This basically creates an instance of the ServerManager class and uses the Add method in the Sites collection to create a new site named "NewSite" listening at port 8080 using http protocol and content files are at d:\MySite.
One thing to note is that calling Update is a requirement since that is the moment when we persist the changes to the configuration store.
After running this code you have now a site that you can browse using http://localhost:8080
Adding an Application to a site
ServerManager iisManager
= new
ServerManager()
;
iisManager.Sites[
"NewSite"
].Applications.Add(
"/Sales"
,
"d:\\MyApp"
)
;
iisManager.Update()
;
This sample uses the Sites collection Indexer to get NewSite site and uses the Applications collection to add a new http://localhost:8080/Sales application.
Creating a Virtual Directory
ServerManager iisManager
= new
ServerManager()
;
Application app
=
iisManager.Sites[
"NewSite"
].Applications[
"/Sales"
]
;
app.VirtualDirectories.Add(
"/VDir"
,
"d:\\MyVDir"
)
;
iisManager.Update()
;
Runtime State and Control
Now, moving on to the new Runtime state and control information we also expose in this objects information about their current state as well as the ability to modify them. For example, we expose the list of W3WP processes running (Worker processes) and what I think is really cool,
we even expose the list of requests currently running
.
Stopping a Web Site
ServerManager iisManager
= new
ServerManager()
;
iisManager.Sites[
"NewSite"
].Stop()
;
Recyciling an Application Pool
ServerManager iisManager
= new
ServerManager()
;
iisManager.ApplicationPools[
"DefaultAppPool"
].Recycle()
;
Getting the list of executing requests
ServerManager iisManager
= new
ServerManager()
;
foreach
(WorkerProcess w3wp
in
iisManager.WorkerProcesses) {
Console.WriteLine(
"W3WP ({0})"
, w3wp.ProcessId)
;
foreach
(Request request
in
w3wp.GetRequests(
0
)) {
Console.WriteLine(
"{0} - {1},{2},{3}"
,
request.Url,
request.ClientIPAddr,
request.TimeElapsed,
request.TimeInState)
;
}
}
Another big thing on this API is the ability to edit the “.config” files using a simple API, this includes the ability of modifying the main applicationHost.config file from IIS, web.config files from asp.net as well as machine.config and other config files (such as administration.config). However I will talk about them in a future post.
56 Comments
IIS
,
.NET
,
Microsoft.Web.Administration
Blog - Comment List MSDN TechNet
Comments
Loading...
Leave a Comment
Name
Comment
Please add 4 and 4 and type the answer here:
Post