« Previous Next »

Answered Thread: Creating IIS 7 Virtual Directory with C# code

Last post 08-25-2010 4:04 PM by pasionador. 10 replies.

 

RSS

Page 1 of 1 (11 items)

Sort Posts:

  • 07-30-2007, 11:33 AM

    • Tom10
    • Not Ranked
    • Joined on 04-26-2006, 1:23 PM
    • Posts 1

    Creating IIS 7 Virtual Directory with C# code

    Hi,

    Using Visual Studio 2005, C#, trying to create Virtual Directory on Windows Vista Enterprise.

    The following function is called from the Installer and should create a virtual directory on the user's local machine.

    All the code works perfectly on Windows XP Pro.

    My C# Code:

            public void CreateVirtualDirectory(string physicalPath, string VDName)
            {

                //Create a virtual directory
                const int MD_AUTH_NT = 0x00000004; //Windows authentication schemes available.
                const int MD_AUTH_ANONYMOUS = 0x00000001; //Anonymous authentication available.

                System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();

                string sError = "";

                vr.Create("IIS://localhost/W3SVC/1/Root", physicalPath, VDName, out sError);

                if (sError.Trim().Length > 0)
                {
                    throw new Exception("Error when creating Virtual Directory:" + Environment.NewLine + sError);
                }

                DirectoryEntry deVDir = new DirectoryEntry("IIS://localhost/W3SVC/1/Root/" + VDName);

                if (deVDir != null)
                {
                    deVDir.Properties["AuthFlags"].Value = MD_AUTH_NT; //MD_AUTH_ANONYMOUS |

                    deVDir.CommitChanges();
                }
                else
                {
                    throw new Exception("Error when creating Virtual Directory:" + Environment.NewLine + "Could not find VD " + VDName);
                }

            }

     The above code throws the error:

    (caused by line:                vr.Create("IIS://localhost/W3SVC/1/Root", physicalPath, VDName, out sError); )

     Log Name:      Application
    Source:        MsiInstaller
    Date:          2007/07/30 03:33:36 PM
    Event ID:      11001
    Task Category: None
    Level:         Error
    Keywords:      Classic
    User:          SOFTCRAFT\moutono
    Computer:      VISTAPC.softcraft.co.za
    Description:
    The description for Event ID 11001 from source MsiInstaller cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

    If the event originated on another computer, the display information had to be saved with the event.

    The following information was included with the event:

    Product: Rivers -- Error 1001. Error 1001: Error when creating Virtual Directory:
    System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.get_IsContainer()
       at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
       at System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName)
       at System.EnterpriseServices.Internal.IISVirtualRoot.Create(String RootWeb, String inPhysicalDirectory, String VirtualDirectory, String& Error)
    (NULL)
    (NULL)
    (NULL)
    (NULL)

    the message resource is present but the message is not found in the string/message table

    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="MsiInstaller" />
        <EventID Qualifiers="0">11001</EventID>
        <Level>2</Level>
        <Task>0</Task>
        <Keywords>0x80000000000000</Keywords>
        <TimeCreated SystemTime="2007-07-30T13:33:36.000Z" />
        <EventRecordID>1479</EventRecordID>
        <Channel>Application</Channel>
        <Computer>VISTAPC.softcraft.co.za</Computer>
        <Security UserID="S-1-5-21-4206377478-2519145661-2763947379-1251" />
      </System>
      <EventData>
        <Data>Product: Rivers -- Error 1001. Error 1001: Error when creating Virtual Directory:
    System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.get_IsContainer()
       at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
       at System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName)
       at System.EnterpriseServices.Internal.IISVirtualRoot.Create(String RootWeb, String inPhysicalDirectory, String VirtualDirectory, String&amp; Error)</Data>
        <Data>(NULL)</Data>
        <Data>(NULL)</Data>
        <Data>(NULL)</Data>
        <Data>(NULL)</Data>
        <Data>
        </Data>
        <Data>
        </Data>
        <Binary>7B33324344464143312D303637302D343939452D394343322D3837463635444435353339367D</Binary>
      </EventData>
    </Event> 

     

     Please help!

     

  • 07-30-2007, 4:49 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 586
    • IIS MVPs

    Answered Re: Creating IIS 7 Virtual Directory with C# code

    Tom,

    Be sure to install the IIS6 Metabase compatibility component of IIS setup to be able to use legacy configuration interfaces like ADSI.

    If you are still having trouble, let us know.

    Thanks,


    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more inside information on IIS7, IIS and ASP.NET

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 08-13-2007, 9:41 AM In reply to

    • valenz4
    • Not Ranked
    • Joined on 08-09-2007, 1:41 PM
    • Posts 1

    Re: Creating IIS 7 Virtual Directory with C# code

    I too am trying to create a virtual directory using c# in Vista. I've tried the above code and it seems to run fine but no virtual directory is ever created.

    Some one please help!!!

  • 08-13-2007, 1:14 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 586
    • IIS MVPs

    Re: Creating IIS 7 Virtual Directory with C# code

    Are you expecting it to actually create a physical folder?  The code above only creates the metabase entry for the virtual directory.  Are you not seeing it when you run:

    > %windir%\system32\inetsrv\appcmd list vdirs 

    This code will require you to install the metabase compatibility as I mentioned above.

    Thanks,

    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more inside information on IIS7, IIS and ASP.NET

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 06-02-2008, 9:39 AM In reply to

    • yaniv101
    • Not Ranked
    • Joined on 06-02-2008, 1:37 PM
    • Posts 2

    Re: Creating IIS 7 Virtual Directory with C# code

    Hi there

    can i define a new virtual directory in by the appcmd,

    and define also the defualt document to load?

    and also i would like to know how can i discuver if
    Internet Information Services>Web Management Tools>IIS 6 Management Compatibility>IIS Metabase and IIS 6 configuration compatibility
     
    is installed?(from registry maby?)
  • 06-02-2008, 8:55 PM In reply to

    • bills
    • Top 25 Contributor
    • Joined on 02-03-2006, 5:33 PM
    • Redmond, WA
    • Posts 433

    Re: Creating IIS 7 Virtual Directory with C# code

  • 06-03-2008, 3:28 AM In reply to

    • yaniv101
    • Not Ranked
    • Joined on 06-02-2008, 1:37 PM
    • Posts 2

    Re: Creating IIS 7 Virtual Directory with C# code

    thank you very much,
     
    that helped alot.
  • 12-04-2008, 5:42 AM In reply to

    • hems4all
    • Not Ranked
    • Joined on 12-04-2008, 10:40 AM
    • Posts 2

    Re: Deleting IIS 6 Virtual Directory with C# code

     Hi i have written the code to delete the virtual directory,
    Note : i want to delete virtual directory from IIS console also.

    this.Message("Delete Virtual Directory.");
    DirectoryEntry root = new DirectoryEntry(rootWeb);
    DirectoryEntry virtualDir = root.Children.Find(virtualDirName); root.Children.Remove(virtualDir);
    root.CommitChanges();
    root.Close();


    this code deletes the virtual directory in 32 bit system on win2k3 but not on win2k3 64 bit system.

    can anybody help me resolve this issue.

    Exception i am getting is :

    System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
    at System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail)
    at System.DirectoryServices.DirectoryEntry.Bind()
    at System.DirectoryServices.DirectoryEntry.get_Schema ClassName()
    at NetIQ.NQACService.ACServiceInstaller.DeleteVirtual Directory(String rootWeb, String virtualDirName)

    if anybody reply it ASAP, will be great help.

  • 12-04-2008, 5:42 AM In reply to

    • hems4all
    • Not Ranked
    • Joined on 12-04-2008, 10:40 AM
    • Posts 2

    Re: Deleting IIS 6 Virtual Directory with C# code

     Hi i have written the code to delete the virtual directory,
    Note : i want to delete virtual directory from IIS console also.

    this.Message("Delete Virtual Directory.");
    DirectoryEntry root = new DirectoryEntry(rootWeb);
    DirectoryEntry virtualDir = root.Children.Find(virtualDirName); root.Children.Remove(virtualDir);
    root.CommitChanges();
    root.Close();


    this code deletes the virtual directory in 32 bit system on win2k3 but not on win2k3 64 bit system.

    can anybody help me resolve this issue.

    Exception i am getting is :

    System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
    at System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail)
    at System.DirectoryServices.DirectoryEntry.Bind()
    at System.DirectoryServices.DirectoryEntry.get_Schema ClassName()
    at NetIQ.NQACService.ACServiceInstaller.DeleteVirtual Directory(String rootWeb, String virtualDirName)

  • 03-25-2010, 7:32 AM In reply to

    • AB1122
    • Not Ranked
    • Joined on 02-25-2010, 12:31 PM
    • Posts 4

    Re: Creating IIS 7 Virtual Directory with C# code

    Hi

    I'm facing the same issue. My component was working fine under IIS 7.0 recently we've migrated to .NET 4.0 and we are getting the "Unknown error (0x80005000)" while performing IIS operations using Directory Services.

    can any one help?

     

    Thanks

     

     

  • 08-25-2010, 4:04 PM In reply to

    Re: Creating IIS 7 Virtual Directory with C# code

     Did any one got this working. This is an issue with permissions right? Because when I run my application that uses DirctoryService it works but I can't execute it from the build machine which is using a different account. I tried setting on that account in the actual web server machine with local admin access and still have the same problem.

Page 1 of 1 (11 items)