|
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
|
|
|
|
|
try
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/alphabeticmetabasepropertylist.asp
its a list of all iis metabase properties
greets, christian
|
|
|
|
|
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 <br />
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. <br />
<br />
Exception Details: System.Runtime.InteropServices.COMException: Access is denied<br />
<br />
Source Error: <br />
<br />
<br />
Line 411: public void CreateVirtualDirectory(string nameDirectory,string realPath)<br />
Line 412: { <br />
Line 413: DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);<br />
Line 414: try<br />
Line 415: {<br />
<br />
<br />
Source File: d:\visual studio project\bsu\components\filenode.cs Line: 413 <br />
<br />
Stack Trace: <br />
<br />
<br />
[COMException (0x80070005): Access is denied]<br />
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)<br />
System.DirectoryServices.DirectoryEntry.Bind()<br />
System.DirectoryServices.DirectoryEntry.get_IsContainer()<br />
System.DirectoryServices.DirectoryEntries.CheckIsContainer()<br />
System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName)<br />
Components.IISManager.CreateVirtualDirectory(String nameDirectory, String realPath) in d:\visual studio project\bsu\components\filenode.cs:413<br />
Components.FileNode.Add(Boolean CreateSubDirectoryNodes) in d:\visual studio project\bsu\components\filenode.cs:282<br />
Site.FileActions.Add.ibSave_Click(Object sender, ImageClickEventArgs e) in d:\visual studio project\bsu\backsite\fileactions\add.aspx.cs:85<br />
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)<br />
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)<br />
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)<br />
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)<br />
System.Web.UI.Page.ProcessRequestMain()<br />
<br />
<br />
<br />
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
|
|
|
|
|
The code you have is pretty good but replace the line
deVDir.Invoke("Delete", null);
with
object[] pars = new object[2];
pars[0] = strSchema;
pars[1] = virtualDirectoryName;
deRoot.Invoke("Delete", pars);
Dan
|
|
|
|
|
I'm using the suggested code to delete a virtual directory, but whenever i get to the 'CommitChanges' line I get an error '{"The system cannot find the path specified." }'. I'm using Win2K.
Any ideas why?
|
|
|
|
|
Hi!
I want to know how i can delete a FTP Virtual directory.
My code is from the link----
http://www.c-sharpcorner.com/Code/2002/July/CreateVirtualDirs.asp
I am creating a Windows Installer thru which i have to create a FTP Virtual directory.
During, uninstall, i have to delete the created FTP Virtula directory.
Pls let me know how to do it..
very urgent.
Here is the code to create the FTP Virtual directory which can also be seen on the link i have given above.
private void button1_Click(object sender, System.EventArgs e)
{
string strSchema= "";
string strRootSubPath = "";
if (radioButton1.Checked)
{
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
}
if (radioButton2.Checked)
{
strSchema = "IIsFtpVirtualDir";
strRootSubPath = "/MSFTPSVC/1/Root";
}
if (strSchema == "")
{
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
}
DirectoryEntry deRoot= new DirectoryEntry("IIS://" + txtServer.Text + strRootSubPath);
try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add(txtVDirName.Text,strSchema);
deNewVDir.Properties["Path"].Insert(0,txtVDir.Text);
deNewVDir.CommitChanges();
deRoot.CommitChanges();
// Create a Application
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("AppCreate",true);
// Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
lblStatus.Text = "Virtual Directory " + txtVDirName.Text + "(" + txtVDir.Text + ") has been created";
}
catch (Exception ex)
{
lblStatus.Text = "Error: " + ex.Message;
}
}
kalh
|
|
|
|
|
Hi!
I want to know how i can delete a FTP Virtual directory.
My code is from the link----
http://www.c-sharpcorner.com/Code/2002/July/CreateVirtualDirs.asp
I am creating a Windows Installer thru which i have to create a FTP Virtual directory.
During, uninstall, i have to delete the created FTP Virtula directory.
Pls let me know how to do it..
very urgent.
Here is the code to create the FTP Virtual directory which can also be seen on the link i have given above.
private void button1_Click(object sender, System.EventArgs e)
{
string strSchema= "";
string strRootSubPath = "";
if (radioButton1.Checked)
{
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
}
if (radioButton2.Checked)
{
strSchema = "IIsFtpVirtualDir";
strRootSubPath = "/MSFTPSVC/1/Root";
}
if (strSchema == "")
{
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
}
DirectoryEntry deRoot= new DirectoryEntry("IIS://" + txtServer.Text + strRootSubPath);
try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add(txtVDirName.Text,strSchema);
deNewVDir.Properties["Path"].Insert(0,txtVDir.Text);
deNewVDir.CommitChanges();
deRoot.CommitChanges();
// Create a Application
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("AppCreate",true);
// Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
lblStatus.Text = "Virtual Directory " + txtVDirName.Text + "(" + txtVDir.Text + ") has been created";
}
catch (Exception ex)
{
lblStatus.Text = "Error: " + ex.Message;
}
}
kalh
|
|
|
|
|
how do i do the same(delete a virtual directory) in VC++.. how to use DirectoryEntry in mfc
|
|
|
|
|
how do i do the same with mfc. i am new to mfc.
Thanks for any help
|
|
|
|
|
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);
}
}
|
|
|
|
|
hello,
i'm not sure what the problem is but perhaps you can help. it creates a virtual directory, sort of but shows a red round error symbal instead of the virtual directory symbal. but if i run it again, the message box comes up telling me a virtual directory already exists. so something in the system thinks its been created but the IIS MMC shows that error icon where the virtual directory should be. i'm running the latest IIS on windows XP. so maybe that's the problem. did you test this with XP?
thanks
Orion
|
|
|
|
|
Although, i didn't test on WinXP, reason may be path problem. If path is not real path, IIS show there icon on red round box. That means you can't access that url.
There are problem in my previos createvdir method. It create vdir on default iis website. It looks fine, but don't execute asp.net webapp. Because, their vdir doesn't have AppName. To create AppName(Really AppFriendlyName), you must run directory's AppCreate method.
Below source is latest code. In my thinking, code works fine. vDir.Invoke method is to run adsi'method. It's very hard to this methodlogy.
You wanna find other iiswebdirectory's property and method, search VS.NET's Online Documentation. When you don't know where it exists, you find 'AppCreate' in search category, and sync location.
Have a nice day, friends...^^;
And sorry my poor english.
public static void CreateVDir(string sPhysicalPath, string sVirDirName)
{
System.DirectoryServices.DirectoryEntry oDE;
System.DirectoryServices.DirectoryEntries oDC;
System.DirectoryServices.DirectoryEntry oVirDir;
string sIISPath;
try
{
sIISPath = "IIS://" + _sHost + "/W3SVC/" + _sServer + "/Root";
oDE = new DirectoryEntry(sIISPath);
oDC = oDE.Children;
oVirDir = oDC.Add(sVirDirName,oDE.SchemaClassName.ToString());
oVirDir.CommitChanges();
oVirDir.Properties["Path"].Value = sPhysicalPath;
oVirDir.Properties["AccessRead"][0] = true;
oVirDir.Invoke("AppCreate",true);
oVirDir.Properties["AppFriendlyName"][0] = sVirDirName;
oVirDir.CommitChanges();
}
catch (Exception exc)
{
throw new Exception(exc.Message);
}
}
|
|
|
|
|
hello,
thanks... actually we got it figured out some time ago. sorry, i probably should have posted a message. for some reason was that a line of code was commented out in your example.
//newVirDir.Invoke("AppCreate",true);
as soon as we ran this line it worked..
thank you
Orion
|
|
|
|
|
Hello ;
You should change
//newVirDir.Invoke("AppCreate",true);
to
newVirDir.Invoke("AppCreate",true);
In other words ,remove comment slashes ,so that the line
is done ; Otherwise you get "Server UnAvaillabe" when trying
to run the application .....
|
|
|
|
|
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
|
|
|
|
|
I was reading some of the above problems and i tired commenting out and uncommenting that line, and it still does the same thing.
when i try to create the directory, and i point it to a directory that exists or that doesn't exist, it DOES create the virtual directory. but the path is not set.
I am on Win XP with IIS 5.1
you're code is really awesome and easy to use... i'm jsut not sure what this problem is. Please help ASAP. thanks
|
|
|
|
|
i had the same problem..... only took 2 hours of playing with it to figure it out......
change "add" to "insert" for the "path" field's value for the creation of the folder path....
(see also: www.steveedwards.net for purchasing C# specific source code or for inquiries about custom development)
|
|
|
|
|
i was having all these problems... by called the CommitChanges() method before calling .Invoke() as well as after
|
|
|
|