 |

|
It successfully creates the virtual directory, but then all other virtual directories cannot be found in IIS including it. IIs gives an error.
---------------------------
Internet Information Services (IIS) Manager
---------------------------
The path is not of a legal form.
---------------------------
OK
---------------------------
I had to modify the project to add the ability to remove the virtual directory in order to restore my dev machine to a usable state.
public void DeleteVirtualDirectory(string nameDirectory, string realPath)
{
DirectoryEntry folderRoot = _iisServer.Children.Find("Root", VirDirSchemaName);
try
{
foreach( DirectoryEntry de in folderRoot.Children )
{
if (de.Name == nameDirectory)
{
folderRoot.Children.Remove(de);
break;
}
}
folderRoot.CommitChanges();
_iisServer.CommitChanges();
}
catch (Exception e)
{
throw new Exception("Virtual Directory " + nameDirectory + " Already Exists", e);
}
}
|
|
|
|

|
I tried to create the virtual directory in the remote machine and I have given the server name as
_serverName = "Remote Machine IP";
public IISManager()
{
_serverName = "172.16.0.46";
}
Im getting the exception "Access Deneid"
|
|
|
|

|
Can I share those folder with outher computers / users over the internet?
Or, Other type of folders / directories..?
Thanks, Gil
|
|
|
|

|
hi,
i am making a window application in vb.net .in that application i want to get the files which are placed in a folder in wwwroot of a remote machine .
how can i do this
please provide me the proper solution.
|
|
|
|
|

|
public void CreateVirtualDirectory(string nameDirectory, string realPath) { DirectoryEntry folderRoot = _iisServer.Children.Find("Root", VirDirSchemaName); try { DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory, VirDirSchemaName); // Set Properties newVirDir.Properties["Path"].Value = realPath; // Create a Application newVirDir.Properties["AppFriendlyName"][0] = nameDirectory;//Application name newVirDir.Properties["AppIsolated"].Value = 2; //"Medium (Pooled)" newVirDir.Properties["AccessScript"][0] = true;//Execute Permission = Scripts Only newVirDir.Invoke("AppCreate", true); // Save Changes newVirDir.CommitChanges(); folderRoot.CommitChanges(); _iisServer.CommitChanges(); } catch (Exception e) { throw new Exception(e.ToString()); } }
|
|
|
|

|
Good article. It got me started but I still wasn't able to turn off anonymous authentication on my existing site.
Here's my solution:
string serverName = System.Environment.MachineName;
// in my case, this was passed in via CustomActionData from my installer
string vDir = Context.Parameters["VirtualDir"];
// Anonymous Authentication bit is 0x00000001
int AnonAuthBitMask = 0x11111110;
DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT/" + vDir);
// apply bit mask to turn off anon auth
iisServer.Properties["AuthFlags"].Value = Convert.ToInt32(iisServer.Properties["AuthFlags"].Value) & AnonAuthBitMask;
// Save changes
iisServer.CommitChanges();
|
|
|
|

|
Hi,
I have used this Code and successfully created Virtual directory in local machine. Now i am trying to create it on Remote machine. i did it by adding some code..
public void CreateVirtualDirectory(string nameDirectory,string realPath)
{
// Newly Added code
_iisServer.Username="myuser";
_iisServer.Password="mypwd";
// Newly Added code
DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);
try
{
DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory,VirDirSchemaName);
newVirDir.Properties["EnableDirBrowsing"].Add(false);
newVirDir.Properties["AppFriendlyName"].Value = nameDirectory;
newVirDir.Properties["DefaultDoc"].Value="default.htm,default.aspx,default.asp";
newVirDir.Properties["Path"].Value = realPath;
// Create a Application
newVirDir.Invoke("AppCreate",true);
// Save Changes
newVirDir.CommitChanges();
folderRoot.CommitChanges();
_iisServer.CommitChanges();
}
catch (Exception e)
{
throw new Exception("Virtual Directory " + nameDirectory + " Already Exists",e);
}
}
but it throws Unknown Name exception.
if i am ignoring newVirDir.Invoke("AppCreate",true); line. means if i do this line commented and then trying then it creates virtual directory but Application is not created so its of no use. and if i am keeping this line then Unknown Name exception arise.. i cant und what to do ?? pl help me..
|
|
|
|

|
Class not worked until I replaced Add methods to Insert
Old scenario: newVirDir.Properties["Path"].Add(realPath)
New scenario: newVirDir.Properties["Path"].Insert(0,realPath)
|
|
|
|

|
good piece of code (thumbs up)
however following is another solution for .net 2.0 ( i m not sure of v1.1
public string DeleteVDir(string metabasePath, string vDirName, string physicalPath)
{
// metabasePath is of the form "IIS://///Root[/]"
// for example "IIS://localhost/W3SVC/1/Root"
// vDirName is of the form "", for example, "MyNewVDir"
// physicalPath is of the form ":\", for example, "C:\Inetpub\Wwwroot"
System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();
string sError;
vr.Delete(metabasePath, physicalPath, vDirName, out sError);
return sError;
}
public string CreateVDir(string metabasePath, string vDirName, string physicalPath)
{
// metabasePath is of the form "IIS://///Root[/]"
// for example "IIS://localhost/W3SVC/1/Root"
// vDirName is of the form "", for example, "MyNewVDir"
// physicalPath is of the form ":\", for example, "C:\Inetpub\Wwwroot"
System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();
string sError;
vr.Create(metabasePath, physicalPath, vDirName, out sError);
return sError;
}
you might have to add reference to enterprise Services
|
|
|
|

|
Dear ALL
I have a problem. I wrote a Web application C#.net to creat a virtual directory. It works fine in windows application mode but showing an error (Catch) Access denied in web application(C#.net). Could any one help me to creat a Virtual directory(IIS) throught C#.net.
My email address is anishasen@yahoo.com
sen K. Mathew
|
|
|
|

|
I want to create virtual directory pointing to another website rather than a directory on the local drive. How can I achieve this?
|
|
|
|
|

|
Hi
well whenever I am running this program I am having a problem that it is unaable to find the path. So can anyone help me with how to define the real path of the virtual directory
|
|
|
|

|
I am running Win2000 Pro and once I run the included demo, it creates the virtual directory but it doesnt show up in the Internet Services Manager. Plus when I try to view a default page that is located in the real path, I get a File Not Found Error. Anyone know why its not working?
Thanks in advance
Kenneth Looney
|
|
|
|

|
I just configured a new "My Web Site" on IIS in addition to the "Default Web Site", and of course, a new port (in my case 2468) is assigned to "My Web Site".
How to use the sample to create a VD in "My Web Site"? I tried to use "localhost:2468", but I got "Unknown error".
|
|
|
|

|
I am trying to set the Application Protection, however I have not been able to find the correct property name.
Can anyone point me in the right direction?
If anyone can do the deletion as well that would be great too.
Thanks in anticipation,
Kent
|
|
|
|

|
I am programming a module for a CMS where you can add a file node to the base structure.
By adding the file node, you need to fill in a Physical Path where the files are located.
But the users cannot access those files from their clients so i need to create a virtual folder referring to this physical path.
I copied the iis manager class to my Business Logic Layer, and tried to create a new virtual folder.
But i get this problem:
Access is denied
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.Runtime.InteropServices.COMException: Access is denied
Source Error:
Line 411: public void CreateVirtualDirectory(string nameDirectory,string realPath)
Line 412: {
Line 413: DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);
Line 414: try
Line 415: {
Source File: d:\visual studio project\bsu\components\filenode.cs Line: 413
Stack Trace:
[COMException (0x80070005): Access is denied]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
System.DirectoryServices.DirectoryEntry.Bind()
System.DirectoryServices.DirectoryEntry.get_IsContainer()
System.DirectoryServices.DirectoryEntries.CheckIsContainer()
System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName)
Components.IISManager.CreateVirtualDirectory(String nameDirectory, String realPath) in d:\visual studio project\bsu\components\filenode.cs:413
Components.FileNode.Add(Boolean CreateSubDirectoryNodes) in d:\visual studio project\bsu\components\filenode.cs:282
Site.FileActions.Add.ibSave_Click(Object sender, ImageClickEventArgs e) in d:\visual studio project\bsu\backsite\fileactions\add.aspx.cs:85
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
I'm really stuk here! Could someone tell me how to correct this problem?
|
|
|
|

|
Now that we can create Cirtual directories, we also want to remove them not only from disk, but from the IIS Management console. I can get the Directory entry removed but when I Invoke "AppDelete" it still remains on the IIS MMC snap-in - any ideas?
Full Source for delete:
string strSchema = "IIsWebVirtualDir";
DirectoryEntry deRoot, deVDir;
string wwwroot = "";
try
{
deRoot= new DirectoryEntry(String.Format("IIS://{0}/W3SVC/1/Root",host));
wwwroot = (string)deRoot.Properties["Path"][0];
}
catch(Exception ex)
{
return false;
}
try
{
deRoot.RefreshCache();
deVDir = deRoot.Children.Find(virtualDirectoryName, strSchema);
if (deVDir == null)
{
deVDir.Close();
deRoot.Close();
return false;
}
else
{
deVDir.Invoke("AppUnload", null);
deVDir.Invoke("AppDelete", null);
string path = (string)deVDir.Properties["Path"][0];
Directory.Delete(path, true);
deVDir.CommitChanges();
deRoot.CommitChanges();
//deVDir.Invoke("Delete", null);
//deVDir.DeleteTree();
deVDir.Close();
deRoot.Close();
return true;
}
}
catch(System.IO.DirectoryNotFoundException)
{
deRoot.Close();
return false;
}
catch (Exception ex)
{
status = String.Format("Error accessing virtual directory:\n{0}. Please select another server.", ex.Message);
deRoot.Close();
return false;
}
-- Art
|
|
|
|

|
Before i have excuted this code in my system.
This code make new virtual directory, but it did not list in my internet information service mmc and did not mapped physical path.
Solution is very easy.
Do not use newVirDir.Invoke in CreateVirtualDirectory method and
replace newVirDir.Properties["Path"].Add(realPath) method to
newVirDir.Properties["Path"].Value = realpath property.
And i add the code newVirDir.CommitChanges() method after newVirDir Instance creation.
this is full method source
public void CreateVirtualDirectory(string nameDirectory,string realPath)
{
DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);
try
{
DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory,VirDirSchemaName);
newVirDir.CommitChanges();
// Set Properties
newVirDir.Properties["AccessRead"].Add(true);
//newVirDir.Properties["Path"].Add(realPath);
newVirDir.Properties["Path"].Value = realPath;
// Create a Application: Don't use invoke method
//newVirDir.Invoke("AppCreate",true);
// Save Changes
newVirDir.CommitChanges();
folderRoot.CommitChanges();
_iisServer.CommitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw new Exception("Virtual Directory " + nameDirectory + " Already Exists",e);
}
}
|
|
|
|

|
Hi,
The virtual directory created does not have the physical path attribute set, which i specify through the application.
I tried the same using my vb6 application and it resulted in the same error. The physical path was not set.
Also, I need to create virtual directory not under the root but under another virtual directory. How can this be done.
I think there is some property of iis which is preventing the physical path being set. I hope you will be able to help me on this.
Thanks
Kannan
|
|
|
|
 |