首页 新闻 会员 周边

请问下在C#中如何实现通过编程配置iis的映射

0
悬赏园豆:20 [已解决问题] 解决于 2013-07-09 10:07
一般在网站中会遇到会用到伪静态,但是这个要添加映射,我目前是直接操作iis的,想请问下通过编程应该怎么实现;还有我这边的silverlight也是直接操作iis的,请问下用编程应该怎么实现!谢谢了
Ben Chan的主页 Ben Chan | 初学一级 | 园豆:3
提问于:2011-10-26 14:31
< >
分享
最佳答案
0

参考代码(来源)

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration appHostConfig = serverManager.GetApplicationHostConfiguration();
ConfigurationSection fastCgiSection = appHostConfig.GetSection("system.webServer/fastCgi");
ConfigurationElementCollection fastCgiCollection = fastCgiSection.GetCollection();
ConfigurationElement applicationElement = fastCgiCollection.CreateElement("application");
applicationElement["fullPath"] = @"c:\php\php-cgi.exe";
fastCgiCollection.Add(applicationElement);

Configuration webConfig = serverManager.GetWebConfiguration("Contoso");
ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");
ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
ConfigurationElement addElement = handlersCollection.CreateElement("add");
addElement["name"] = @"PHP-FastCGI";
addElement["path"] = @"*.php";
addElement["verb"] = @"GET,HEAD,POST";
addElement["modules"] = @"FastCgiModule";
addElement["scriptProcessor"] = @"c:\php\php-cgi.exe";
addElement["resourceType"] = @"Either";
handlersCollection.AddAt(0, addElement);

serverManager.CommitChanges();
}
}
}

其他参考文章:

Use C# to manage IIS

Adding a ScriptMap object using ManagementClasses

收获园豆:20
dudu | 高人七级 |园豆:30994 | 2011-10-26 14:54

学习了

artwl | 园豆:16736 (专家六级) | 2011-10-26 19:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册