打开IIS,点开左边的默认网战,在上边单击右键选择,然后按说明步骤进行

解决方案 »

  1.   

    我问的是我用程序建的虚拟目录怎么在IIS中不可见?
      

  2.   

    wideroad
    不要开玩笑了,我想知道的是如何在程序中建立
      

  3.   

    大哥们,我现在很郁闷,搞了一天,也没有看到。但是用find的方法却能找到。希望大家指教啊。
      

  4.   

    to:meetweb(niky)
    能具体点吗?
      

  5.   

    你的代码并未包含建虚拟目录的部分呀.
    我有一段小玩艺, 请笑纳.using System;
    using System.DirectoryServices;namespace JoeM.Utilites.VirtualDirectory
    {
    /// <summary>
    /// Summary description for IISManager.
    /// </summary>
    public class IISManager
    {
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="serverName">Name of the IIS Server</param>
    public IISManager(string serverName)
    {
    _serverName = serverName;
    }
    /// <summary>
    /// Default constructor uses localhost as default server
    /// </summary>
    public IISManager()
    {
    _serverName = "localhost";
    }

    /// <summary>
    /// Connect to IISServer
    /// </summary>
    public void Connect()
    {
                try
    {
    _iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");
    }
    catch (Exception e)
    {
    throw new Exception("Could not connect to: " + _serverName,e);
    }
    } /// <summary>
    /// Create a virtual directory
    /// </summary>
    /// <param name="nameDirectory">Name of the new virtual directory</param>
    /// <param name="realPath">Path of the directory</param>
    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["AccessRead"].Add(true);
    newVirDir.Properties["Path"].Add(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);
    }
    }

    #region Properties
    public string ServerName
    {
    get
    {
    return _serverName;
    }
    set
    {
    _serverName = value;
    }
    }
    #endregion

    public static string VirDirSchemaName = "IIsWebVirtualDir";

    #region Private Members
            private string _serverName;
    private DirectoryEntry _iisServer;
    #endregion
    }
    }
      

  6.   

    哦。我自己解决了饿。哈哈代码如下:
    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);
    }
    }