Setting default page in deployment

  • Thread starter Thread starter QDL
  • Start date Start date
Q

QDL

Hello everyone,

is there a way to programmatically set the default document from a
deployment project for ASP.NET. My default page is named default.htm and I'd
like to set it as the topmost default document in IIS site properties using
the deployment project, is this possible? Tried to google but found no
answer.

TIA
Paolo
 
You can do this by exporting the IIS settings and actually installing them
on the server in question. I do not have a working example right now, but
will see if I have anything written up on it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
 
You can do this by exporting the IIS settings and actually installing them
on the server in question. I do not have a working example right now, but
will see if I have anything written up on it.

Thanx Cowboy for answering, will appreciate if you have a sample but anyway,
you pointed me the right way... I thought there was something in the
Deployment project to obtain that but I was wrong...

Thanx
Paolo
 
I answer myself as I found the way and may be helpful to some1:

1. In deployment project add CustomAction for OnCommit specify
InstallerClass=True and add parameter /vdir="[TARGETVDIR]"

2. Add an installer class to your aspnet project and insert this override:

Private Const EnableDefaultDoc = &H40000000&

Protected Overrides Sub OnCommitted(ByVal savedState As
System.Collections.IDictionary)
Dim folderRoot, vdir As DirectoryEntry
Dim vdirname As String

Try
vdirname = Me.Context.Parameters("vdir")

folderRoot = New DirectoryEntry("IIS://localhost/W3SVC/1/Root")
folderRoot.RefreshCache()

vdir = folderRoot.Children.Find(vdirname, folderRoot.SchemaClassName)

vdir.Properties("DirBrowseFlags").Value =
vdir.Properties("DirBrowseFlags").Value Or EnableDefaultDoc
vdir.Properties("DefaultDoc").Value = "default.htm"

vdir.CommitChanges()
folderRoot.CommitChanges()
Catch ex As Exception
Finally
If (Not vdir Is Nothing) Then
vdir.Close()
End If

If (Not folderRoot Is Nothing) Then
folderRoot.Close()
End If
End Try
End Sub

This will enable default documents and add default.htm as the only default
document. Of course can be changed.

Hope someone will be helped by this

Paolo
 
Back
Top