PDA

Click to See Complete Forum and Search --> : Create Virtual Directory in IIS using VB.NET


Wokawidget
Jun 30th, 2005, 04:41 AM
You need to add a reference into your app for System.DirectoryServices
Then use:

Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String)

Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated")
Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
IISSchema.Dispose()

If CanCreate Then
Dim PathCreated As Boolean

Try
Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

'make sure folder exists
If Not System.IO.Directory.Exists(Path) Then
System.IO.Directory.CreateDirectory(Path)
PathCreated = True
End If

'If the virtual directory already exists then delete it
For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children
If VD.Name = AppName Then
IISAdmin.Invoke("Delete", New String() {VD.SchemaClassName, AppName})
IISAdmin.CommitChanges()
Exit For
End If
Next VD

'Create and setup new virtual directory
Dim VDir As System.DirectoryServices.DirectoryEntry = IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
VDir.Properties("Path").Item(0) = Path
VDir.Properties("AppFriendlyName").Item(0) = AppName
VDir.Properties("EnableDirBrowsing").Item(0) = False
VDir.Properties("AccessRead").Item(0) = True
VDir.Properties("AccessExecute").Item(0) = True
VDir.Properties("AccessWrite").Item(0) = False
VDir.Properties("AccessScript").Item(0) = True
VDir.Properties("AuthNTLM").Item(0) = True
VDir.Properties("EnableDefaultDoc").Item(0) = True
VDir.Properties("DefaultDoc").Item(0) = "default.htm,default.aspx,default.asp"
VDir.Properties("AspEnableParentPaths").Item(0) = True
VDir.CommitChanges()

'the following are acceptable params
'INPROC = 0
'OUTPROC = 1
'POOLED = 2
VDir.Invoke("AppCreate", 1)

Catch Ex As Exception
If PathCreated Then
System.IO.Directory.Delete(Path)
End If
Throw Ex
End Try
End If
End Sub

This is used in the following way:

CreateVirtualDir("LocalHost", "Woof", "C:\MyWebProjects\Woof")

This creates a Virtual Dir called Woof on the LocalHost server and points and the path C:\MyWebProjects\Woof on the hard drive.

Hope this helps.

Woka

nizmo
Jul 19th, 2005, 07:34 PM
That code is exactly what i was after, and it works fine on the primary domain controller machine - but when i try and run it on our new web server i get the error

"The RPC server is unavailable"

On this line;
Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"


The RPC service IS started on the server in question.
Its driving me crazy, you gotta help me!

Wokawidget
Jul 19th, 2005, 08:56 PM
I tried Googling it for you, but there are sooooo many different reasons for it not working....from having a virus on the PC to renaming your computer after IIS has been installed.

Here's the search link I used:

http://www.google.com/search?hl=en&lr=&q=%22The+RPC+server+is+unavailable%22+and+IIS

It's 2am here, and I need Zzzzz for an early start.

Let us know if you find the solution. If you haven't posted back here by tomorrow morning, 10am-ish GMT, then I'll look through all those search results and see what I come up with.

Woof

nizmo
Jul 21st, 2005, 11:53 PM
Hey

Thanks heaps for replying, and yeah google returned too many possibilities, but we figured it out in the end. It was the windows firewall that was preventing me from doing a rpc to the sever, probably because of the ports. Since our web server has another 2 outer layers of firewall protection, the standard windows firewall wasnt required and so we just leave it off now

Ah man you wouldnt believe how much nicer it is being able to click one button to roll out 6 new versions of our product instead of having to terminal services into the server, delete the 6 shares, share the 6 new folders, refresh the website node, right click each of the 6 new versions of the app and go to properties to apply permissions etc etc.

Thanks heaps, you're code has saved me so much time and frustration.

Oh yeah, and hopefully i replied in time so you didnt have to search through the google results - if not, then im sorry about that :/

Wokawidget
Jul 22nd, 2005, 04:50 AM
No problems...We thought the same here...made life sooo much easier for us.
I did search google and was testing stuff out yesterday, but ended up in lots of meetings and stuff then got caught up in writting some code so we could write our UI at work.

Glad it's fixed though.

What was the error and I'll add a try catch thing to my code.

Woka

uniquegodwin
Aug 23rd, 2005, 11:02 PM
Hey..
the "System.DirectoryServices.DirectoryEntry" namespace doesnt work for me..what should i do?

Thanks

uniquegodwin
Aug 23rd, 2005, 11:04 PM
I mean that namespace doesnt exist on my computer..Is there some reference you added or something?

Wokawidget
Aug 24th, 2005, 04:37 AM
You need to add a reference to System.DirectoryServices

Sorry, myfaul...should have mentioned that in my 1st post :(

Woof

uniquegodwin
Aug 24th, 2005, 05:26 AM
No no,the code is Great.. :) Thanks

uniquegodwin
Aug 24th, 2005, 05:30 AM
Will this work even if IIS is not installed on the users machine?

Wokawidget
Aug 24th, 2005, 06:59 AM
errrr....no :confused:

Woka

uniquegodwin
Aug 24th, 2005, 07:19 AM
:) but still,I really appreciate this code you've done.Its really good :) Thanks.

AProgrammer
Oct 10th, 2005, 06:48 AM
The Code is really awesome but I have a necessity where I want to Create or Add or Delete Virtual Directories or Web Sites. Any Help Possible???????

san011070
Nov 7th, 2005, 01:34 AM
Thx so much for this code. Keep it up!

I just wanna know if it needs full .NET installed or only the .NET framwork?

Sanjiv

Wokawidget
Nov 7th, 2005, 04:49 AM
U would need the .NET framework and some form of VB.NET compiler. MS do one for free. But dunno what it's called.

Woka

skillsrhodes
Dec 2nd, 2005, 12:04 PM
Thanks so much for this code, it works great. My question is, if I want to build a virtual dir in a non-default web site, what's the best way to go about doing it?

I think I need to do something like this, right?

Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/N/Root")

Where N is the correct number to address the web site I'm looking for. Is there a way to determine what that number is in VB?

Thanks

Adam

bw3740
Dec 13th, 2005, 05:40 PM
I used this to find the correct site id:
---------------------------------------
Dim SiteID As Integer
Dim root As New System.DirectoryServices.DirectoryEntry("IIS://" & ServerName & "/W3SVC")

For Each e As System.DirectoryServices.DirectoryEntry In root.Children
If e.SchemaClassName.ToUpper = "IISWEBSERVER" AndAlso CStr(e.Invoke("Get", "ServerComment")).ToUpper = SiteName.ToUpper Then
SiteID = Convert.ToInt32(e.Name)
Exit For
End If
Next

Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & ServerName & "/W3SVC/" & SiteID & "/Root")

chipslvsv
Dec 19th, 2005, 05:49 PM
Hello I have used this code but when I try to Create de Virtual Directory I get a System.UnauthorizedAccessException: Access is denied error saying something about the ASP.NET anonymous use required permissions etc.

I'm running an IIS 5.1 Server on Windows 2000 Server.

I don't know where is suposed to give the permissions to the user. Maybe someone can help me Thaks..

duynnh
Jun 29th, 2006, 11:41 AM
Hi All!
I am using this code but i have an Error: "System.UnauthorizedAccessException: Access is denied", help me!
Regards,

Wokawidget
Jun 29th, 2006, 01:07 PM
Probably because your accounts don't have permissions. Pass a valid username and password to the:

Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated", "Administrator", "Woka123")

I am assuming it's that line of code.

Woka

txghia58
Aug 3rd, 2006, 03:56 PM
Any idea of how to set the .Net version that the virtual directory is using?

myabhishek
Aug 21st, 2006, 09:22 AM
Hi All!
I am using this code but i have an Error: "System.UnauthorizedAccessException: Access is denied", help me!
Regards,

-------------------------------

When i am trying to create a virtual directory using the above code - i get the following error

System.UnauthorizedAccessException was unhandled by user code
Message="Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
Source="System.DirectoryServices"
StackTrace:
at _Default.CreateVirtualDir(String WebSite, String AppName, String Path) in c:\inetpub\wwwroot\VirtualWebSite\Default.aspx.vb:line 84
at _Default.btnCreateDirectory_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\VirtualWebSite\Default.aspx.vb:line 9
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


--------------

Please help

Wokawidget
Aug 22nd, 2006, 06:13 AM
Can you post your code...

Woka

beepmaster
Aug 23rd, 2006, 11:24 AM
I tried to implement this code and can get it to work on one of my Web sites on my development IIS server. However, the only one it works on is the local host. I am actually developing 7 Web sites off of my server and need to create the virtual directories on a different Web site. How do I point the virtual directory to the right Web site?

Also, are there any security risks with having this function available over the Web that I should be concerned about? (Stupid question?)

Wokawidget
Aug 23rd, 2006, 09:30 PM
Not sure how to do it remotely.

There are security risks with anything...but I don't think it can be done over the web, and if they could, then they could also login to your svr because they would need the username and password.

Woof

beepmaster
Aug 24th, 2006, 10:40 AM
Also, is it possible to (instead of specifying a file location) to specify a redirect page?

wizbay
Sep 8th, 2006, 02:36 AM
Woka, I read your article about creating virtual directory in vbforum.com.

This is an amazing code I was looking for long time. I am developing with visual studio 2005 on windows xp pro system.

This code works if I build it using development server in visual studio 2005 (Ctrl + F5) but it would not work on win xp's iis server. It occurs "System.UnauthorizedAccessException: Access is denied".

I tried your suggestion
(Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated", "Administrator", "Woka123"))
and others, too but nothing works.

Do you have any other suggestions? I get this working on my desktop, can I make this working on my webhosting account? (shared hosting)

If this is not working, can you tell me how to make a folder an application root in vb.net?

Wokawidget
Sep 8th, 2006, 05:40 AM
Have you used the servers admin and password?

Woka

wizbay
Sep 8th, 2006, 05:15 PM
Yes I used the username and password.

You mean the username and password I use to log on to Windows xp right?

My account has admin's permission.

wizbay
Sep 10th, 2006, 04:56 PM
Is this code wokring for IIS 6.0 and higher only?

5.1 or earlier version doesn't work?

Wokawidget
Sep 10th, 2006, 06:20 PM
only tested on 6 I am afraid :(

WOka

wizbay
Sep 13th, 2006, 12:42 AM
Okay. I finally installed windows 2003 standard with IIS 6.0.
I used default created web.config and had directoryservices referenced.

But unfortunately, I still have exactly same error. I will be more detail this time Woka.

Here's link to my ftp server for my source codes. http://wizbay.com/woka.zip

Please don't give me up~

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
</html>

Default.aspx.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.DirectoryServices

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

CreateVirtualDir("localhost", "test", "e:\test")

End If

End Sub
Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String)

'Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated")
Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated", "Administrator", "1212")

Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
IISSchema.Dispose()

If CanCreate Then
Dim PathCreated As Boolean

Try
Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

'make sure folder exists
If Not System.IO.Directory.Exists(Path) Then
System.IO.Directory.CreateDirectory(Path)
PathCreated = True
End If

'If the virtual directory already exists then delete it
For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children
If VD.Name = AppName Then
IISAdmin.Invoke("Delete", New String() {VD.SchemaClassName, AppName})
IISAdmin.CommitChanges()
Exit For
End If
Next VD

'Create and setup new virtual directory
Dim VDir As System.DirectoryServices.DirectoryEntry = IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
VDir.Properties("Path").Item(0) = Path
VDir.Properties("AppFriendlyName").Item(0) = AppName
VDir.Properties("EnableDirBrowsing").Item(0) = False
VDir.Properties("AccessRead").Item(0) = True
VDir.Properties("AccessExecute").Item(0) = True
VDir.Properties("AccessWrite").Item(0) = False
VDir.Properties("AccessScript").Item(0) = True
VDir.Properties("AuthNTLM").Item(0) = True
VDir.Properties("EnableDefaultDoc").Item(0) = True
VDir.Properties("DefaultDoc").Item(0) = "default.htm,default.aspx,default.asp"
VDir.Properties("AspEnableParentPaths").Item(0) = True
VDir.CommitChanges()

'the following are acceptable params
'INPROC = 0
'OUTPROC = 1
'POOLED = 2
VDir.Invoke("AppCreate", 1)

Catch Ex As Exception
If PathCreated Then
System.IO.Directory.Delete(Path)
End If
Throw Ex
End Try
End If
End Sub

End Class


Error on http://localhost/Default.aspx
Access denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[UnauthorizedAccessException: Access denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))]
_Default.CreateVirtualDir(String WebSite, String AppName, String Path) +1238
_Default.Page_Load(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

beepmaster
Sep 15th, 2006, 01:25 PM
All, I was finally able to spend some time to answer my question about how to specify which Web site on the IIS server I wanted to create the Virtual Directory for. In the following line of code, the "1" is the identifier for which Web site you are referring to. You can get this number by left clicking on the Website folder. To the right, the screen should now list all of your Web sites and there is an identifier column. That is the value that should be there.

Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

Hope that makes sense.

beepmaster
Sep 29th, 2006, 10:11 AM
I was getting this error, but I think I have solved it. I'm not sure it's the best solution, because apparently it opens up some security issues, but it has to do with the application pool you are using for the Web site. If you go to the Web site's application pool's properties and select the identity tag you will see a drop down box next to the "predefined" radio button. Select "Local system" and click apply.

If all your code is set up correctly, you should be all set. I don't know what (if any) security risks are opened. Microsoft just throws up a warning when you do this. Let me know if you find anything on that, I'd be very interested to hear what they have to say.

Okay. I finally installed windows 2003 standard with IIS 6.0.
I used default created web.config and had directoryservices referenced.

But unfortunately, I still have exactly same error. I will be more detail this time Woka.

Here's link to my ftp server for my source codes. http://wizbay.com/woka.zip

Please don't give me up~

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
</html>

Default.aspx.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.DirectoryServices

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

CreateVirtualDir("localhost", "test", "e:\test")

End If

End Sub
Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String)

'Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated")
Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated", "Administrator", "1212")

Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
IISSchema.Dispose()

If CanCreate Then
Dim PathCreated As Boolean

Try
Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

'make sure folder exists
If Not System.IO.Directory.Exists(Path) Then
System.IO.Directory.CreateDirectory(Path)
PathCreated = True
End If

'If the virtual directory already exists then delete it
For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children
If VD.Name = AppName Then
IISAdmin.Invoke("Delete", New String() {VD.SchemaClassName, AppName})
IISAdmin.CommitChanges()
Exit For
End If
Next VD

'Create and setup new virtual directory
Dim VDir As System.DirectoryServices.DirectoryEntry = IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
VDir.Properties("Path").Item(0) = Path
VDir.Properties("AppFriendlyName").Item(0) = AppName
VDir.Properties("EnableDirBrowsing").Item(0) = False
VDir.Properties("AccessRead").Item(0) = True
VDir.Properties("AccessExecute").Item(0) = True
VDir.Properties("AccessWrite").Item(0) = False
VDir.Properties("AccessScript").Item(0) = True
VDir.Properties("AuthNTLM").Item(0) = True
VDir.Properties("EnableDefaultDoc").Item(0) = True
VDir.Properties("DefaultDoc").Item(0) = "default.htm,default.aspx,default.asp"
VDir.Properties("AspEnableParentPaths").Item(0) = True
VDir.CommitChanges()

'the following are acceptable params
'INPROC = 0
'OUTPROC = 1
'POOLED = 2
VDir.Invoke("AppCreate", 1)

Catch Ex As Exception
If PathCreated Then
System.IO.Directory.Delete(Path)
End If
Throw Ex
End Try
End If
End Sub

End Class


Error on http://localhost/Default.aspx
Access denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[UnauthorizedAccessException: Access denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))]
_Default.CreateVirtualDir(String WebSite, String AppName, String Path) +1238
_Default.Page_Load(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

Passgad
Mar 22nd, 2007, 02:22 PM
The original code create a Web application under wwwroot.

Someone knows how to create juste a virtual directory (not a web application) with the Browse option ?

For an example, I've created a virtual dir from the wizard in IIS 6 :

http://www.passgad.net/eps/iis.jpg


What is the code for this ?

Thanks,
Pass

Wokawidget
Mar 23rd, 2007, 06:50 AM
Your screen shot isnt showing...but I think this may do what you want:

Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal NewDirName As String, ByVal Path As String)

Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated")
Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
IISSchema.Dispose()

If CanCreate Then
Dim PathCreated As Boolean

Try
Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

'make sure folder exists
If Not System.IO.Directory.Exists(Path) Then
System.IO.Directory.CreateDirectory(Path)
PathCreated = True
End If

'If the virtual directory already exists
Dim appFound As Boolean = False

For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children
If VD.Name = AppName Then
appFound = True

'Create and setup new virtual directory
Dim VDir As System.DirectoryServices.DirectoryEntry = VD.Children.Add(NewDirName, "IIsWebVirtualDir")
VDir.Properties("Path").Item(0) = Path

VDir.Properties("EnableDirBrowsing").Item(0) = False
VDir.Properties("AccessRead").Item(0) = True
VDir.Properties("AccessExecute").Item(0) = True
VDir.Properties("AccessWrite").Item(0) = False
VDir.Properties("AccessScript").Item(0) = True

VDir.CommitChanges()

Exit For
End If
Next VD

If Not appFound Then
Throw New Exception("Web Application not found.")
End If

Catch Ex As Exception
If PathCreated Then
System.IO.Directory.Delete(Path)
End If
Throw Ex
End Try
End If
End Sub

Then call using:

CreateVirtualDir("LocalHost", "Woof", "Growl", "C:\MyWebProjects\Woof\Growl")

I already have a virtual directory called Woof under the default web site.

Woka

h.annous
Apr 26th, 2007, 08:28 AM
Wonderful, thank you.

I was wondering if it is possible to edit the Directory Security (Anonymous access and authentication control) in order to make sure only basic authentication and Integrated Windows security are checked for example.

h.annous
Apr 26th, 2007, 10:06 AM
I figured it out myself, thanks.
AuthNTLM for Integrated Windows.
AuthBasic for basic authentication.

Wokawidget
Apr 26th, 2007, 10:20 AM
You beat me to it, I was just this second about to post that :D

Woof

h.annous
Apr 27th, 2007, 03:27 AM
:-)
What is the way to get the names of all the properties?

Wokawidget
Apr 27th, 2007, 04:02 AM
Just loop through all the props out output the name.

woof

h.annous
Apr 27th, 2007, 05:05 AM
I'm a little new to VB.NET.
The properties collection is of type PropertyCollection.
What's the type of each of the elements (the one to use in the for each loop)?

RobM
Apr 27th, 2007, 11:53 AM
I think this will give you what you need.


link (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/5e429d06-1735-4db4-842f-c32c2edbc25e.asp)

Thanks for the code. It was exactly what I was looking for.

jignesh_1508
Jul 27th, 2007, 06:39 AM
i dopied source code for creating virtual directory in IIS of local server . but if i want to Create in IIS of another PC using IP adderess ,what should i change in that code??? anyone plssss i m new user ...

h.annous
Jul 27th, 2007, 08:05 AM
Instead of LocalHost pass the IP address.

jignesh_1508
Aug 1st, 2007, 03:09 AM
hi,i can create virtual directory in IIS .but i want to create a New website i.e.www.testing.com. how can i create using vb.net any idea plz plz tell me.....

thanx in Advance

Wokawidget
Aug 1st, 2007, 05:12 AM
Take a look at:

http://forums.asp.net/p/396812/857211.aspx#857211

Woka

jignesh_1508
Aug 2nd, 2007, 02:18 AM
thanks woka.
i want ur suggestion.
what should i use in my project .
MYSQL or microsoft's SQL server as backend in .NET????
if i want to use MYSQL as backend which technology should i prefer?
apache/PHP or .NET??

Wokawidget
Aug 2nd, 2007, 06:11 AM
I would have to always say IIS, .NET and MS SQL Svr.

Wokawidget
Aug 2nd, 2007, 06:12 AM
...then again...it completely depends on what project you are writting. MS SQL Svr my be complete overkill for very very small projects.

Woka

jignesh_1508
Aug 3rd, 2007, 04:59 AM
hi, woka
i m creating job searching website.
jobseekers can resume their CV,search for vaccancies..etc..etc..
it is very big Project..

if i use My SQL as a backend ,will it create any problem(i.e.like speed slow,efficiency etc.)??

i don't want to use MS SQL Server as a backend.

Wokawidget
Aug 3rd, 2007, 07:02 AM
I am not that familiar with My SQL I am afraid.
Why don't you want to use SQL Svr?

Woka

jignesh_1508
Aug 3rd, 2007, 08:02 AM
hi, woka

i m working on the project as per the client requirement. my client wants to use my sql as a backend. do u have any idea plssss??

Wokawidget
Aug 3rd, 2007, 08:26 AM
Ideas on what?
If your client wants My SQL then use My SQL...I wudn't. I would use SQL Svr...MSDE 2000 or MSDE 2005 Express.
My SQL won't cause you any issues I don't think, it's just not as good as SQL Server.

You want to be asking these kind of questions in the DB section...you'll get a bigger response.

Woka

blacksheep1980
Aug 29th, 2007, 12:25 PM
Hi Chaps,

I'm new to this site and registered purely on the back of this excellent piece of work to create virtual directories in VB.NET.

But, I'm having a problem with the RPC issue.

I can't just turn the firewall off (company policy I'm afraid! :ehh: ).

Is there any further developments with getting round this RPC issue? Are there any exceptions I should set within Windows Firewall to allow this IIS change from the application I've created?

For further information, the error I receive is this:-

System.Runtime.InteropServices.COMExeption occured in system.directoryservices.dll

Additional information: The RPC server is unavailable.

This occurs on the following line within the code:

Dim CanCreate as Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "Boolean"

Any help would be really appreciated!

Thanks

Wokawidget
Aug 30th, 2007, 05:57 AM
Hi and welcome :wave:

This is a tricky one. It can be caused by many many things. Firewalls just being one of them
Does your company use a 3rd party firewall? If so, turning off the windows firewall may fix the issue.
Not exactly sure what ports need to be open I am afraid :(

If you run this on the web server itself do you get the errors?

Woka

blacksheep1980
Aug 30th, 2007, 08:19 AM
I'm not sure exactly how their firewall is set up. It's quite a big company (British Telecom!!! lol).

I'm writing a system to automate the installation of a web application we have developed. Part of the automation is to manipulate IIS and create the virtual directories.

The script has been ran from the web server itself (i.e. localhost) but still this RPC error is returned.

I will do some investigating myself and if I find a solution I'll post it. I'm not holding my breath though! :rolleyes:

Cheers

Wokawidget
Aug 31st, 2007, 04:43 AM
hehe. BT. I was working there not so long ago and they have some of the most locked down environments I have ever seen.
Have you heard of HMC, Hosted Message Collaboration? or MPS, Microsoft Provisioning System?
I did some overview dev training on these products for BT a few months ago.
MPS was designed to provision resources in your environment...any resources.
Have a word with ppl at BT and see if they have heard of HMC....if so, use that :D

So, you also got the error on the local IIS box? :( doesn't sound good.
Does the local IIS box have windows firewall running?

Woka

larock
Oct 8th, 2007, 12:49 AM
In order for the App Name to be populated correctly, you have to swap these two lines
VDir.CommitChanges()
VDir.Invoke("AppCreate", 1)

Should be
VDir.Invoke("AppCreate", 1)
VDir.CommitChanges()

If you don't swap the two lines, the AppFriendlyName will appear blank when you look at the properties of your Virtual Directoy.

Other than that, excellent code. Thanks

Wokawidget
Oct 8th, 2007, 03:20 AM
Good bug spot. Thanks :D

sadame
Feb 15th, 2008, 11:41 AM
Hi Woka..
I only registered to this site to say thank you for the post. Two years later and it's still working and helping people like me. Thank you to all of you. I rewrite the code in c# but for some reason I couldn't figure out it's not working. So I decided to write it in VB.Net and use it as a DLL, which is working perfectly. Weird isn't it?

---
Sergio

mark@markkiessling.c
Sep 22nd, 2008, 07:21 PM
I was wondering if anyone knows how to add an IIS 6 web site with Host Header?

Chibikishi
Jul 16th, 2010, 04:49 PM
Hi Woka! Thanks for letting us use the code I really appreciate it. The code seemed to be working when I was running it through visual studios, but after we uploaded onto the server I am getting the RPC unavailable error. I'm not sure what to do to fix this, we checked the firewall and are logging in as administrator so I'm not sure what else can be the problem. Do you have any ideas? Here is the stack trace error that follows:
[COMException (0x800706ba): The RPC server is unavailable.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +377678
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_AdsObject() +31
System.DirectoryServices.PropertyValueCollection.PopulateList() +26
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +49
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +150
MFC.WebApp.SecureAuth.WebAdminWorkflow.CreateVirtualDir(String WebSite, String AppName, String Path) +192
MFC.WebApp.SecureAuth.WebAdminWorkflow.AddInstanceButton_Click(Object sender, EventArgs e) +239
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Chibikishi
Jul 16th, 2010, 06:23 PM
Nevermind I found what was wrong. I was hardcoding the name for my box while I was coding instead of putting the localhost name. Everything seems to be working fine now