Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anybody know please help me.
How can i setup IIS on win7 programically using C# to run classic asp file.
I have success on windows xp but it's not run on win7.
any advice needed.

1 solution

Share this answer
zhongzhe 15-Sep-11 5:25am    
Thank you very much.
It would be greate help for me.
But I have some errors while excuting following codes.
public static bool AddVirtualDirectory(string siteName, string application, string virtualDirectoryPath, string physicalPath, string userName, string password)
if (string.IsNullOrEmpty(siteName))
throw new ArgumentNullException("siteName", "AddVirtualDirectory: siteName is null or empty.");
if (string.IsNullOrEmpty(application))
throw new ArgumentNullException("application", "AddVirtualDirectory: application is null or empty.");
if (string.IsNullOrEmpty(virtualDirectoryPath))
throw new ArgumentNullException("virtualDirectoryPath", "AddVirtualDirectory: virtualDirectoryPath is null or empty.");
if (string.IsNullOrEmpty(physicalPath))
throw new ArgumentNullException("physicalPath", "AddVirtualDirectory: physicalPath is null or empty.");
using (ServerManager mgr = new ServerManager())
Site site = mgr.Sites[siteName];
if (site != null)
Application app = site.Applications[application];
if (app != null)
VirtualDirectory vDir = app.VirtualDirectories[virtualDirectoryPath];
if (vDir != null)
throw new Exception("Virtual Directory: " + virtualDirectoryPath + " already exists.");
vDir = app.VirtualDirectories.CreateElement();
vDir.Path = virtualDirectoryPath;
vDir.PhysicalPath = physicalPath;
if (!string.IsNullOrEmpty(userName))
if (string.IsNullOrEmpty(password))
throw new Exception("Invalid Virtual Directory User Account Password.");
vDir.UserName = userName;
vDir.Password = password;
return true;
throw new Exception("Application: " + application + " does not exist.");
throw new Exception("Site: " + siteName + " does not exist.");
catch (Exception ex)
throw new Exception(ex.Message, ex);
Thanks again.
Pradeep Shukla 15-Sep-11 11:26am    
You have not mentioned the error that you are getting. Can you provide it with the line no on which you have the error?
zhongzhe 20-Sep-11 5:13am    
Sorry with delay response.

I have success setup iis and add virtual directory programically using some prompt commands.

string command = "attrib -r c:\\windows\\system32\\inetsrv\\config\\redirection.config";
string command1 = "c:/windows/system32/inetsrv/appcmd add vdir /" + '\u0022' + "Default Web Site/" + '\u0022' + " /path:/" + txtName.Text + " /physicalPath:" + txtPath.Text;
Thank you very much with your help.

But I can't understand why this not allow to run classic asp even virtual direcotries are finded in IIS manager correctly.

If I access to virtual directory on IE , it always display HTTP error 500.19 - Internal Server Error.

Many thanks.
zhongzhe 20-Sep-11 5:37am    
I already set config of IIS to run asp files.(install by checking asp in controll panel)

It's very strange to me.
But I expect you it 's easy issue for you and help me.
best regards.
Pradeep Shukla 20-Sep-11 14:15pm    
Classic ASP script error messages are no longer shown in a Web browser by default. Make sure the "Send Errors To Browser" attribute is set to True(IIS Manager->Click your website->Click ASP icon in the Home page->Expand the list of ASP features), then reproduce this issue. There should be some meaningful error message in the browser which can help us determine the root cause.
The following article contains more information, for your reference:
Running Classic ASP Applications on IIS 7.0 and IIS 7.5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900