Configuring IIS using VB.net code

  • Thread starter Thread starter Andrew Raastad
  • Start date Start date
A

Andrew Raastad

Greetings,

Running into a situation here that is a little beyond my grasp. We have a
web-based product which currently configured and targeted for IIS6. We're
in that transition stage where we want to migrate, or at least open it up to
IIS7. Our product gets installed using a custom installer (WinForm
application project) in what I guess you could call three main steps. The
last step does some configuration to IIS setting up domains, mapping DLLs,
setting application extensions, etc.

The configuration methods use COM Interop by performing late binding to
objects that point to the various properties and such of IIS. For example,
we needed to increase the allotted size for uploading files. The main
method sets an object to be used for this and then calls a help method:

Dim websvc As Object = GetObject("IIS://localhost/W3svc/1")
SetUploadSize(websvc)

Then the modification is done in a helper method like this:

Private Sub SetUploadSize(ByVal websvc As Object)
Try
'Set Maximum file upload in bytes
If websvc.AspMaxRequestEntityAllowed <= 204800 Then
websvc.AspMaxRequestEntityAllowed = 10485760
websvc.SetInfo()
End If

Catch ex As Exception
Throw New Exception("MicrosoftIIS:SetUploadSize() Failed:" &
vbCrLf & ex.ToString)

End Try
End Sub

This type of process is used to set Application Extensions, handlers for
DLLs, and more. But while this works ok on our Windows 2003 Servers running
IIS6, it blows sky high on a box with IIS7 giving the error:

System.Runtime.InteropServices.COMException (0x800CC801): Exception from
HRESULT: 0x800CC801
at
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean
IgnoreReturn)

I do not understand what the problem is let alone how to fix it. I am not
totally certain it is moving from IIS6 to IIS7 that is the cause but maybe
from Windows Server 2003 to Server2008/Vista?? Your thoughts, suggestions??


On a side note....

Doing additional research it was pointed out to me that there is an
alternative way to accomplish this - using the System.DirectoryServices
Namespace
(http://msdn.microsoft.com/en-us/library/system.directoryservices.aspx) but
I am having trouble gleaning anything from it that is like what I need to do
here. A second site that was pointed out to me
(http://www.codersource.net/csharp_iis_metabase.html) describes with some
code how to access the IIS MetaBase, but it really doesn't go into all that
much detail on how to accomplish much beyond adding/deleting a virtual
directory or file. While this looks to do the virtual directory items I
need, how do I set DLL Handlers, Application Extensions, modify the allowed
upload size, etc.?

Is there a class or set of classes I can import into the project that
'simplifies' the manipulation or configuration of IIS?

Never having messed with IIS outside the IIS Manager before, I guess I am
just feeling a bit overwhelmed here. Your help and input is greatly
appreciated!

-- Andrew
 
For those playing the home version...

I have been able to successfully convert the old code over to using
Directory Services to interact with the IIS Metabase to accomplish all that
I needed to do. What I needed to do were five things: 1) Create a few
virtual directories, 2) Modify the allowed upload size of files to the
server through IIS, 3) Add a MIME type to IIS, 4) Add a DLL handler to the
application extension list for a custom file extension, and 5) Add a new DLL
Handler to the Web Service Extensions for IIS. No small task, considering I
had never done this before, (1 & 2 by hand through the manager but never
using code, and the others not at all), let alone do it through Directory
Services... which I have only dabbled with in the past.

Through recommendations, suggestions, and research on Google, I would like
to share what I came up with to accomplish this.

For #1, creating Virtual Directories, it is based on a site suggested to me,
but I put it into a reusable method as I needed to add a lot of directories:

''' <summary>
''' Creates a new Virtual Directory within the IIS Metabase
''' </summary>
''' <param name="IISPath">Path to the Root folder</param>
''' <param name="PhysicalPath">Physical path to the files on
disk</param>
''' <param name="FolderName">Name of folder to be created</param>
''' <param name="AccessRead">Allow Read Access</param>
''' <param name="AccessWrite">Allow Write Access</param>
''' <param name="AccessScript">Allow Script Access</param>
''' <param name="AccessExecute">Allow Execute Access</param>
''' <remarks></remarks>
Public Sub CreateVirtualDirectory(ByVal IISPath As String, ByVal
PhysicalPath As String, ByVal FolderName As String, ByVal AccessRead As
Boolean, ByVal AccessWrite As Boolean, ByVal AccessScript As Boolean, ByVal
AccessExecute As Boolean)
Try
Dim Parent As New DirectoryEntry(IISPath)
Dim NewVirtualDirectory As DirectoryEntry

NewVirtualDirectory = Parent.Children.Add(FolderName,
"IIsWebVirtualDir")
With NewVirtualDirectory
.Properties("Path")(0) = PhysicalPath
.Properties("AccessScript")(0) = AccessScript
.Properties("AccessRead")(0) = AccessRead
.Properties("AccessWrite")(0) = AccessWrite
.Properties("AccessExecute")(0) = AccessExecute
.CommitChanges()
End With

Catch ex As Exception
Throw New Exception("CreateVirtualDirectory() Failed:" &
vbCrLf & ex.ToString)

End Try
End Sub

Example usage would be:

Dim IISRootFolder As String = "IIS://localhost/w3svc/1/root" ' *** 1 =
Website ID#
CreateVirtualDirectory(IISRootFolder, "C:\WebImages", "images", True, True,
False, False)

For #2, modifying the allowed upload size, I started from example code I
found on the MSDN library here:
http://msdn.microsoft.com/en-us/library/ms525791.aspx but tailored it to
fit my needs:

''' <summary>
''' Updates a single property value within the IIS Metabase
''' </summary>
''' <param name="MetaBasePath">Path to the Metabase property</param>
''' <param name="PropertyName">Name of property to change</param>
''' <param name="NewValue">New value for the property</param>
''' <remarks></remarks>
Private Sub SetSingleValue(ByVal MetaBasePath As String, ByVal
PropertyName As String, ByVal NewValue As String)
Try
Dim Path As New DirectoryEntry(MetaBasePath)
Path.Properties(PropertyName)(0) = NewValue
Path.CommitChanges()

Catch ex As Exception
Throw New Exception("SetSingleValue() Failed:" & vbCrLf &
ex.ToString)

End Try
End Sub

Here is the property I needed to change (by default it is around 20KB, I
needed larger, approx 10MB):

SetSingleValue("IIS://localhost/w3svc/1", "AspMaxRequestEntityAllowed",
"10485760")


For #3, adding a MIME type, it is a little more complicated, but still
pretty straight forward. However, it does require you add a reference to
the COM Object: "Active DS IIS Namespace Provider"

''' <summary>
''' Sets a new Mime Type in the IIS metabase
''' </summary>
''' <param name="MetabasePath">Path to the IIS Metabase</param>
''' <param name="NewExtension">New extension for the Mime
Type</param>
''' <param name="NewMimeType">Mime Type to be used</param>
''' <remarks></remarks>
Private Sub SetMimeTypeProperty(ByVal MetabasePath As String, ByVal
NewExtension As String, ByVal NewMimeType As String)
Try
Dim Path As New DirectoryEntry(MetabasePath)
Dim PropValues As PropertyValueCollection =
Path.Properties("MimeMap")
Dim Exists As Object = Nothing

' Check to see if the extension currently exists
For Each Value As Object In PropValues
Application.DoEvents()
' IISOle requires a reference to the Active DS IIS
Namespace Provider in Visual Studio .NET
Dim mimetypeObj As IISOle.IISMimeType = CType(Value,
IISOle.IISMimeType)
If NewExtension = mimetypeObj.Extension Then
Exists = Value
Exit For
End If
Next

' Clear the old extension if it exists before continuing
If Exists IsNot Nothing Then
PropValues.Remove(Exists)
End If

' Create the new extension
Dim NewObj As IISOle.MimeMapClass = New IISOle.MimeMapClass
NewObj.Extension = NewExtension
NewObj.MimeType = NewMimeType
PropValues.Add(NewObj)
Path.CommitChanges()

Catch ex As Exception
Throw New Exception("SetMimeTypeProperty() Failed:" & vbCrLf
& ex.ToString)

End Try
End Sub

Change the extension and type for your needs, but the way we used it:

SetMimeTypeProperty("IIS://localhost/w3svc/1/root", ".*",
"application/octet-stream")

In IIS6, the MIME type is found by opening the IIS Manager, open the
properties for your Web, go to the HTTP Headers tab, and click the MIME
Types button at the bottom right. In IIS7, open the IIS Manager (make sure
you have it set to Features View), click on your Web, then double-click the
MIME Types icon under the IIS category/section


For #4, adding an application file extension DLL Handler, the code is not
that much different from above, just updating values in a different area of
the Metabase.

''' <summary>
''' Adds a new application extension mapping to the IIS Metabase
''' </summary>
''' <param name="MetaBase">Path to the IIS Metabase</param>
''' <param name="NewScript">New extension map script</param>
''' <remarks></remarks>
Private Sub SetApplicationExtension(ByVal MetaBase As String, ByVal
NewScript As String)
Try
Dim Path As New DirectoryEntry(MetaBase)
Dim PropValues As PropertyValueCollection =
Path.Properties("ScriptMaps")
Dim Exists As Object = Nothing

' Check to see if the Script Mapping already exists
For Each Value As Object In PropValues
Application.DoEvents()
' Check to see if the extension is already mapped
If CStr(Value).Split(",")(0) = NewScript.Split(",")(0)
Then
Exists = Value
Exit For
End If
Next

' Remove the mapping is it exists
If Exists IsNot Nothing Then
PropValues.Remove(Exists)
End If

' Add the new script
PropValues.Add(NewScript)

' Commit changes
Path.CommitChanges()

Catch ex As Exception
Throw New Exception("SetApplicationExtension() Failed:" &
vbCrLf & ex.ToString)

End Try
End Sub

An example of how we used this:

SetApplicationExtension("IIS://localhost/w3svc/1/root", ".[extension],[path
to DLL].dll,1")

You don't have to add the "GET,POST" etc. verbs unless you need to, IIS will
simply add "ALL" for you.


And lastly for #5, adding a Web Service Extension, the code is again very
similar to above:

''' <summary>
''' Adds a new web extension mapping to the IIS Metabase
''' </summary>
''' <param name="Metabase">Path to the IIS Metabase</param>
''' <param name="NewWebExtension">Web Extension value</param>
''' <remarks></remarks>
Private Sub SetWebExtension(ByVal Metabase As String, ByVal
NewWebExtension As String)
Try
Dim Path As New DirectoryEntry(Metabase)
Dim PropValues As PropertyValueCollection =
Path.Properties("WebSvcExtRestrictionList")
Dim Exists As Boolean = False

' Check if the web extension alreay exists
For Each Value As Object In PropValues
Application.DoEvents()
' Check to see if the mapping exists
If CStr(Value) = NewWebExtension Then
Exists = True
Exit For
End If
Next

' Add the new extension if it doesn't exist
If Not Exists Then
PropValues.Add(NewWebExtension)
Path.CommitChanges()
Path.Invoke("EnableWebServiceExtension", "ASP")
End If

Catch ex As Exception
Throw New Exception("SetWebExtension() Failed:" & vbCrLf &
ex.ToString)

End Try
End Sub

How we used this was:

SetWebExtension("IIS://localhost/w3svc", "1,[path to DLL].dll" & ",1,[SWE
Title],[SWE Extension Name]")
For the first part of the string: 1 = Allow, 0 = Prohibit

In IIS6 the Web Service Extensions are found by opening the IIS Manager,
expanding the local computer and clicking on the Web Service Extension node.
In IIS7 the name has been changed so it's a little more difficult to locate
at first, but open the IIS Manager, click on the local computer node, and
then double-click the "ISAPI and CGI Restrictions" icon under the IIS
category/section.


There is likely tons more you can do through the use of the
DirectoryServices class to manage IIS, but the above did what I needed to,
and works in both IIS6 and IIS7. Oh, one note.... you'll see
"Application.DoEvents" in all the loops, that was because I was running a
status bar and didn't want it to stop while a loop was encountered.

Use these if you like or have a need, change, modify, or alter to suit
whatever you need. If you add to it, modify it, or improve on it, post it
back in here so we all can benefit. Thanks!

-- Andrew




Andrew Raastad said:
Greetings,

Running into a situation here that is a little beyond my grasp. We have a
web-based product which currently configured and targeted for IIS6. We're
in that transition stage where we want to migrate, or at least open it up
to IIS7. Our product gets installed using a custom installer (WinForm
application project) in what I guess you could call three main steps. The
last step does some configuration to IIS setting up domains, mapping DLLs,
setting application extensions, etc.

The configuration methods use COM Interop by performing late binding to
objects that point to the various properties and such of IIS. For
example, we needed to increase the allotted size for uploading files. The
main method sets an object to be used for this and then calls a help
method:

Dim websvc As Object = GetObject("IIS://localhost/W3svc/1")
SetUploadSize(websvc)

Then the modification is done in a helper method like this:

Private Sub SetUploadSize(ByVal websvc As Object)
Try
'Set Maximum file upload in bytes
If websvc.AspMaxRequestEntityAllowed <= 204800 Then
websvc.AspMaxRequestEntityAllowed = 10485760
websvc.SetInfo()
End If

Catch ex As Exception
Throw New Exception("MicrosoftIIS:SetUploadSize() Failed:"
& vbCrLf & ex.ToString)

End Try
End Sub

This type of process is used to set Application Extensions, handlers for
DLLs, and more. But while this works ok on our Windows 2003 Servers
running IIS6, it blows sky high on a box with IIS7 giving the error:

System.Runtime.InteropServices.COMException (0x800CC801): Exception from
HRESULT: 0x800CC801
at
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean
IgnoreReturn)

I do not understand what the problem is let alone how to fix it. I am not
totally certain it is moving from IIS6 to IIS7 that is the cause but maybe
from Windows Server 2003 to Server2008/Vista?? Your thoughts,
suggestions??


On a side note....

Doing additional research it was pointed out to me that there is an
alternative way to accomplish this - using the System.DirectoryServices
Namespace
(http://msdn.microsoft.com/en-us/library/system.directoryservices.aspx)
but I am having trouble gleaning anything from it that is like what I need
to do here. A second site that was pointed out to me
(http://www.codersource.net/csharp_iis_metabase.html) describes with some
code how to access the IIS MetaBase, but it really doesn't go into all
that much detail on how to accomplish much beyond adding/deleting a
virtual directory or file. While this looks to do the virtual directory
items I need, how do I set DLL Handlers, Application Extensions, modify
the allowed upload size, etc.?

Is there a class or set of classes I can import into the project that
'simplifies' the manipulation or configuration of IIS?

Never having messed with IIS outside the IIS Manager before, I guess I am
just feeling a bit overwhelmed here. Your help and input is greatly
appreciated!

-- Andrew
 
For those playing the home version...

I have been able to successfully convert the old code over to using
Directory Services to interact with the IIS Metabase to accomplish all that
I needed to do. What I needed to do were five things: 1) Create a few
virtual directories, 2) Modify the allowed upload size of files to the
server through IIS, 3) Add a MIME type to IIS, 4) Add a DLL handler to the
application extension list for a custom file extension, and 5) Add a new DLL
Handler to the Web Service Extensions for IIS. No small task, considering I
had never done this before, (1 & 2 by hand through the manager but never
using code, and the others not at all), let alone do it through Directory
Services... which I have only dabbled with in the past.

Through recommendations, suggestions, and research on Google, I would like
to share what I came up with to accomplish this.

For #1, creating Virtual Directories, it is based on a site suggested to me,
but I put it into a reusable method as I needed to add a lot of directories:

''' <summary>
''' Creates a new Virtual Directory within the IIS Metabase
''' </summary>
''' <param name="IISPath">Path to the Root folder</param>
''' <param name="PhysicalPath">Physical path to the files on
disk</param>
''' <param name="FolderName">Name of folder to be created</param>
''' <param name="AccessRead">Allow Read Access</param>
''' <param name="AccessWrite">Allow Write Access</param>
''' <param name="AccessScript">Allow Script Access</param>
''' <param name="AccessExecute">Allow Execute Access</param>
''' <remarks></remarks>
Public Sub CreateVirtualDirectory(ByVal IISPath As String, ByVal
PhysicalPath As String, ByVal FolderName As String, ByVal AccessRead As
Boolean, ByVal AccessWrite As Boolean, ByVal AccessScript As Boolean, ByVal
AccessExecute As Boolean)
Try
Dim Parent As New DirectoryEntry(IISPath)
Dim NewVirtualDirectory As DirectoryEntry

NewVirtualDirectory = Parent.Children.Add(FolderName,
"IIsWebVirtualDir")
With NewVirtualDirectory
.Properties("Path")(0) = PhysicalPath
.Properties("AccessScript")(0) = AccessScript
.Properties("AccessRead")(0) = AccessRead
.Properties("AccessWrite")(0) = AccessWrite
.Properties("AccessExecute")(0) = AccessExecute
.CommitChanges()
End With

Catch ex As Exception
Throw New Exception("CreateVirtualDirectory() Failed:" &
vbCrLf & ex.ToString)

End Try
End Sub

Example usage would be:

Dim IISRootFolder As String = "IIS://localhost/w3svc/1/root" ' *** 1 =
Website ID#
CreateVirtualDirectory(IISRootFolder, "C:\WebImages", "images", True, True,
False, False)

For #2, modifying the allowed upload size, I started from example code I
found on the MSDN library here:
http://msdn.microsoft.com/en-us/library/ms525791.aspx but tailored it to
fit my needs:

''' <summary>
''' Updates a single property value within the IIS Metabase
''' </summary>
''' <param name="MetaBasePath">Path to the Metabase property</param>
''' <param name="PropertyName">Name of property to change</param>
''' <param name="NewValue">New value for the property</param>
''' <remarks></remarks>
Private Sub SetSingleValue(ByVal MetaBasePath As String, ByVal
PropertyName As String, ByVal NewValue As String)
Try
Dim Path As New DirectoryEntry(MetaBasePath)
Path.Properties(PropertyName)(0) = NewValue
Path.CommitChanges()

Catch ex As Exception
Throw New Exception("SetSingleValue() Failed:" & vbCrLf &
ex.ToString)

End Try
End Sub

Here is the property I needed to change (by default it is around 20KB, I
needed larger, approx 10MB):

SetSingleValue("IIS://localhost/w3svc/1", "AspMaxRequestEntityAllowed",
"10485760")


For #3, adding a MIME type, it is a little more complicated, but still
pretty straight forward. However, it does require you add a reference to
the COM Object: "Active DS IIS Namespace Provider"

''' <summary>
''' Sets a new Mime Type in the IIS metabase
''' </summary>
''' <param name="MetabasePath">Path to the IIS Metabase</param>
''' <param name="NewExtension">New extension for the Mime
Type</param>
''' <param name="NewMimeType">Mime Type to be used</param>
''' <remarks></remarks>
Private Sub SetMimeTypeProperty(ByVal MetabasePath As String, ByVal
NewExtension As String, ByVal NewMimeType As String)
Try
Dim Path As New DirectoryEntry(MetabasePath)
Dim PropValues As PropertyValueCollection =
Path.Properties("MimeMap")
Dim Exists As Object = Nothing

' Check to see if the extension currently exists
For Each Value As Object In PropValues
Application.DoEvents()
' IISOle requires a reference to the Active DS IIS
Namespace Provider in Visual Studio .NET
Dim mimetypeObj As IISOle.IISMimeType = CType(Value,
IISOle.IISMimeType)
If NewExtension = mimetypeObj.Extension Then
Exists = Value
Exit For
End If
Next

' Clear the old extension if it exists before continuing
If Exists IsNot Nothing Then
PropValues.Remove(Exists)
End If

' Create the new extension
Dim NewObj As IISOle.MimeMapClass = New IISOle.MimeMapClass
NewObj.Extension = NewExtension
NewObj.MimeType = NewMimeType
PropValues.Add(NewObj)
Path.CommitChanges()

Catch ex As Exception
Throw New Exception("SetMimeTypeProperty() Failed:" & vbCrLf
& ex.ToString)

End Try
End Sub

Change the extension and type for your needs, but the way we used it:

SetMimeTypeProperty("IIS://localhost/w3svc/1/root", ".*",
"application/octet-stream")

In IIS6, the MIME type is found by opening the IIS Manager, open the
properties for your Web, go to the HTTP Headers tab, and click the MIME
Types button at the bottom right. In IIS7, open the IIS Manager (make sure
you have it set to Features View), click on your Web, then double-click the
MIME Types icon under the IIS category/section


For #4, adding an application file extension DLL Handler, the code is not
that much different from above, just updating values in a different area of
the Metabase.

''' <summary>
''' Adds a new application extension mapping to the IIS Metabase
''' </summary>
''' <param name="MetaBase">Path to the IIS Metabase</param>
''' <param name="NewScript">New extension map script</param>
''' <remarks></remarks>
Private Sub SetApplicationExtension(ByVal MetaBase As String, ByVal
NewScript As String)
Try
Dim Path As New DirectoryEntry(MetaBase)
Dim PropValues As PropertyValueCollection =
Path.Properties("ScriptMaps")
Dim Exists As Object = Nothing

' Check to see if the Script Mapping already exists
For Each Value As Object In PropValues
Application.DoEvents()
' Check to see if the extension is already mapped
If CStr(Value).Split(",")(0) = NewScript.Split(",")(0)
Then
Exists = Value
Exit For
End If
Next

' Remove the mapping is it exists
If Exists IsNot Nothing Then
PropValues.Remove(Exists)
End If

' Add the new script
PropValues.Add(NewScript)

' Commit changes
Path.CommitChanges()

Catch ex As Exception
Throw New Exception("SetApplicationExtension() Failed:" &
vbCrLf & ex.ToString)

End Try
End Sub

An example of how we used this:

SetApplicationExtension("IIS://localhost/w3svc/1/root", ".[extension],[path
to DLL].dll,1")

You don't have to add the "GET,POST" etc. verbs unless you need to, IIS will
simply add "ALL" for you.


And lastly for #5, adding a Web Service Extension, the code is again very
similar to above:

''' <summary>
''' Adds a new web extension mapping to the IIS Metabase
''' </summary>
''' <param name="Metabase">Path to the IIS Metabase</param>
''' <param name="NewWebExtension">Web Extension value</param>
''' <remarks></remarks>
Private Sub SetWebExtension(ByVal Metabase As String, ByVal
NewWebExtension As String)
Try
Dim Path As New DirectoryEntry(Metabase)
Dim PropValues As PropertyValueCollection =
Path.Properties("WebSvcExtRestrictionList")
Dim Exists As Boolean = False

' Check if the web extension alreay exists
For Each Value As Object In PropValues
Application.DoEvents()
' Check to see if the mapping exists
If CStr(Value) = NewWebExtension Then
Exists = True
Exit For
End If
Next

' Add the new extension if it doesn't exist
If Not Exists Then
PropValues.Add(NewWebExtension)
Path.CommitChanges()
Path.Invoke("EnableWebServiceExtension", "ASP")
End If

Catch ex As Exception
Throw New Exception("SetWebExtension() Failed:" & vbCrLf &
ex.ToString)

End Try
End Sub

How we used this was:

SetWebExtension("IIS://localhost/w3svc", "1,[path to DLL].dll" & ",1,[SWE
Title],[SWE Extension Name]")
For the first part of the string: 1 = Allow, 0 = Prohibit

In IIS6 the Web Service Extensions are found by opening the IIS Manager,
expanding the local computer and clicking on the Web Service Extension node.
In IIS7 the name has been changed so it's a little more difficult to locate
at first, but open the IIS Manager, click on the local computer node, and
then double-click the "ISAPI and CGI Restrictions" icon under the IIS
category/section.


There is likely tons more you can do through the use of the
DirectoryServices class to manage IIS, but the above did what I needed to,
and works in both IIS6 and IIS7. Oh, one note.... you'll see
"Application.DoEvents" in all the loops, that was because I was running a
status bar and didn't want it to stop while a loop was encountered.

Use these if you like or have a need, change, modify, or alter to suit
whatever you need. If you add to it, modify it, or improve on it, post it
back in here so we all can benefit. Thanks!

-- Andrew




Andrew Raastad said:
Greetings,

Running into a situation here that is a little beyond my grasp. We have a
web-based product which currently configured and targeted for IIS6. We're
in that transition stage where we want to migrate, or at least open it up
to IIS7. Our product gets installed using a custom installer (WinForm
application project) in what I guess you could call three main steps. The
last step does some configuration to IIS setting up domains, mapping DLLs,
setting application extensions, etc.

The configuration methods use COM Interop by performing late binding to
objects that point to the various properties and such of IIS. For
example, we needed to increase the allotted size for uploading files. The
main method sets an object to be used for this and then calls a help
method:

Dim websvc As Object = GetObject("IIS://localhost/W3svc/1")
SetUploadSize(websvc)

Then the modification is done in a helper method like this:

Private Sub SetUploadSize(ByVal websvc As Object)
Try
'Set Maximum file upload in bytes
If websvc.AspMaxRequestEntityAllowed <= 204800 Then
websvc.AspMaxRequestEntityAllowed = 10485760
websvc.SetInfo()
End If

Catch ex As Exception
Throw New Exception("MicrosoftIIS:SetUploadSize() Failed:"
& vbCrLf & ex.ToString)

End Try
End Sub

This type of process is used to set Application Extensions, handlers for
DLLs, and more. But while this works ok on our Windows 2003 Servers
running IIS6, it blows sky high on a box with IIS7 giving the error:

System.Runtime.InteropServices.COMException (0x800CC801): Exception from
HRESULT: 0x800CC801
at
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean
IgnoreReturn)

I do not understand what the problem is let alone how to fix it. I am not
totally certain it is moving from IIS6 to IIS7 that is the cause but maybe
from Windows Server 2003 to Server2008/Vista?? Your thoughts,
suggestions??


On a side note....

Doing additional research it was pointed out to me that there is an
alternative way to accomplish this - using the System.DirectoryServices
Namespace
(http://msdn.microsoft.com/en-us/library/system.directoryservices.aspx)
but I am having trouble gleaning anything from it that is like what I need
to do here. A second site that was pointed out to me
(http://www.codersource.net/csharp_iis_metabase.html) describes with some
code how to access the IIS MetaBase, but it really doesn't go into all
that much detail on how to accomplish much beyond adding/deleting a
virtual directory or file. While this looks to do the virtual directory
items I need, how do I set DLL Handlers, Application Extensions, modify
the allowed upload size, etc.?

Is there a class or set of classes I can import into the project that
'simplifies' the manipulation or configuration of IIS?

Never having messed with IIS outside the IIS Manager before, I guess I am
just feeling a bit overwhelmed here. Your help and input is greatly
appreciated!

-- Andrew
 
Back
Top