C#: Access is denied when adding virtual FTP directory to IIS

  • Thread starter Thread starter Vincent Mouton
  • Start date Start date
V

Vincent Mouton

Hi,

I am trying to add an FTP Virtual Directory to IIS through C# code in an
ASP.NET page.
I'm getting an Access Denied Error when running the code below. I've left
out the code adding the directory itself.
For debugging purposes I tried to only execute the code below
(RefreshCache();), and even then I received that error.
From the beginning on, I've added the Username and Password property to the
DirectoryEntry instance.
See my code below.
note: target, username and password are parameters passed through a method
that holds this code.

DirectoryEntry folderRoot = new DirectoryEntry("IIS://" + target +
"/MSFTPSVC/1/Root");
folderRoot.Username = username;
folderRoot.Password = password;
folderRoot.RefreshCache();


Right before executing this, I managed to add a user account using this
instance of DirectoryEntry class.

DirectoryEntry AD = new DirectoryEntry("WinNT://" + target +
",computer",username,password);
(....)

And I managed to add a New Website in IIS (not a virtual directory) using an
WMI wrapper (ManagementClass, ManagementObject, etc...).
With the same UserName and Password as I tried to use to add the FTP virtual
directory.

thank you in advance,
Vincent
 
Spawn a thread with a user identity that has these rights. The other option
is giving the ASP.NET worker process and IUSR god-like rights (which means
any hacker is a god on your system).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
"Vincent Mouton"
 
Hi,

sorry for my very late reply. I think the first solution is by far the bast
(no god messing with my security).

thanks for your insights!
Vincent
 
Back
Top