1

Is it possible to create a virtual folder in IIS from an ASP.NET site?

Sample: I have a website http://www.example.com/myApp and from within that application, I want to create http://www.example.com/userfiles123 (and point it to a actual folder somewhere else on the machine)

If not, any other suggestions on how to schedule a "create virtual directory" command from an asp.net page?

2 Answers 2

2

DirectoryServices can be used to connect to IIS and create Virtual Directories.

I found this bit of script on Codersource.net used to create a Virtual Directory:

public void CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, bool AccessScript){
      DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
      DirectoryEntry NewVirtualDir;
      NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir");
      NewVirtualDir.Properties["Path"][0] = Path;
      NewVirtualDir.Properties["AccessScript"][0] = AccessScript;
      NewVirtualDir.CommitChanges();
}

Also found an example in ASP.NET just like you wanted. See this blog post for more information and downloadable code.

Sign up to request clarification or add additional context in comments.

Comments

0

suppose this is ur path

  • C:\Inetpub\wwwroot\WebSite1

then do this

go to iis and select the websites----then in that expand the default website ---- then rightclick the ourwebsite name and -----select new from that and give virtual directory and tehn there give the permisssions in the sharing and then-- give the alias name to that ------then apply and ok then expand the website name and in the wizard select our default.aspx file and explore tyaht one then it will be hosted

1 Comment

My question is how do I do this from code, not how to do it in IIS manager.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.