Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.
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.
James.
Posted

1 solution

 
Share this answer
 
Comments
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)
{
try
{
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.");
}
else
{
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.");
else
{
vDir.UserName = userName;
vDir.Password = password;
}
}
app.VirtualDirectories.Add(vDir);
}
mgr.CommitChanges();
return true;
}
else
throw new Exception("Application: " + application + " does not exist.");
}
else
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";
runCommand(command);
string command1 = "c:/windows/system32/inetsrv/appcmd add vdir /app.name:" + '\u0022' + "Default Web Site/" + '\u0022' + " /path:/" + txtName.Text + " /physicalPath:" + txtPath.Text;
runCommand(command1);
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    
Hi,
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
http://learn.iis.net/page.aspx/559/running-classic-asp-applications-on-iis-70-and-iis-75/

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