|
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);
}
}
|
|
|
|
|
That is because this code is for dotNet1.0 and is light-years away from being compatible with Windows 7 and newer versions of dotNet.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
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..
|
|
|
|
|
please help me i am also getting the same error , did u get the solution
|
|
|
|
|
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)
|
|
|
|
|
hi,
thanks for ur finding...
|
|
|
|
|
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)<br />
{<br />
System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();<br />
string sError;<br />
vr.Delete(metabasePath, physicalPath, vDirName, out sError); <br />
return sError; <br />
}<br />
public string CreateVDir(string metabasePath, string vDirName, string physicalPath)<br />
{<br />
System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();<br />
string sError;<br />
vr.Create(metabasePath, physicalPath, vDirName, out sError);<br />
return sError;<br />
}
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 got similar one, but that's bad when noone find an answer for this
|
|
|
|
|
hi guys,
pls look carefully above posts...
u can use Insert() instead of Add()
cheer
|
|
|
|
|
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
|
|
|
|
|
Make sure the "Virtual Directory" is actually a Virtual Directory, I'm having the same problem in VS.NET 2003 Pro with the same OS as you. I found the fix here:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21309471.html
Basically I had to create the VD again manually.
|
|
|
|
|
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".
|
|
|
|
|
You will need to find out what the correct IISPath is.
This method i created, lists all the websites currently installed on your IIS.
<br />
public static DataTable getAllWebsites()<br />
{<br />
DataTable dt = new DataTable();<br />
dt.Columns.Add(new DataColumn("IISPATH", typeof(string)));<br />
dt.Columns.Add(new DataColumn("Name", typeof(string)));<br />
dt.Columns.Add(new DataColumn("DisplayName", typeof(string)));<br />
dt.Columns.Add(new DataColumn("Path", typeof(string))); <br />
<br />
DataRow dr;<br />
string MachineName = "localhost";<br />
string IIsObjectPath = "IIS://" + MachineName + "/w3svc";<br />
const string WebServerSchema = "IIsWebServer";
<br />
<br />
DirectoryEntry IIsObject = new DirectoryEntry(IIsObjectPath); <br />
<br />
DirectoryEntry SiteRoot;<br />
foreach (DirectoryEntry Site in IIsObject.Children) <br />
{<br />
if (Site.SchemaClassName == WebServerSchema)<br />
{<br />
SiteRoot = new DirectoryEntry(Site.Path + "/Root");<br />
<br />
dr = dt.NewRow();<br />
dr["IIsPath"] = Site.Path;<br />
dr["Name"] = Site.Properties["ServerComment"].Value.ToString(); <br />
dr["Path"] = SiteRoot.Properties["Path"].Value.ToString();<br />
dr["DisplayName"] = SiteRoot.Path + "-" + Site.Properties["ServerComment"].Value.ToString(); <br />
<br />
dt.Rows.Add(dr);<br />
}<br />
} <br />
return dt;<br />
}<br />
Just bind it to a datagrid... '
goodluck
|
|
|
|
|
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
|
|
|
|