来个生僻点的:如何在ASP.NET站点中获取这个站点应用程序池的配置值?

大飞飞虫 2012-02-21 05:09:16
我在IIS中建一个站点名字为 myweb, 为这个站点指定应用程序池 myapp。


我想在myweb站点c#程序中读取应用程序池myapp的配置,然后做不同的处理,例如读到这个[enable 32-bit applications]标记的值是true还是false:


该如何写代码,或者请你提示下用什么类就可以了。

好久没提问了,谢谢!
...全文
220 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
大飞飞虫 2012-02-22
  • 打赏
  • 举报
回复
谢谢各位了。虽然不是那么直接,但是至少有了方向了
大飞飞虫 2012-02-22
  • 打赏
  • 举报
回复
再谢一下,至此我已经搞定了。确实可以得到这个属性值,为更多人参考拿出来分享下:

DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool = appPool.Children.Find("Prodika v6.1.1.0", "IIsApplicationPool");

string b = "";
foreach (string a in findPool.Properties.PropertyNames)
{
b += string.Format("{0}={1}\n", a, findPool.InvokeGet(a));
}

return b;

可以得到如下值,其中就有我要的:
AppPoolIdentityType=0
AppPoolState=2
Win32Error=0
AppPoolCommand=1
KeyType=IIsApplicationPool
AppPoolAutoStart=True
Enable32BitAppOnWin64=True //我就是要这个
ManagedPipelineMode=1

★★注意,启动进程池的账号必须有‘管理员’权限,否则会报 access is denied.
习惯就好 2012-02-21
  • 打赏
  • 举报
回复


不好意思上面好像实现不了你效果

http://msdn.microsoft.com/zh-cn/library/microsoft.web.administration.applicationpool.aspx

你己己研究下
wosizy 2012-02-21
  • 打赏
  • 举报
回复
果然很生僻

/需要添加应用程序池空间引用
using System.DirectoryServices;

string method="Start"; //Start开启 Recycle回收 Stop 停止
string AppPoolName = "chengxuchiname";
try
{
    DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
    DirectoryEntry findPool = appPool.Children.Find(AppPoolName,"IIsApplicationPool");
    findPool.Invoke(method,null);
    appPool.CommitChanges();
    appPool.Close();
MessageBox.Show("应用程序池名称启动成功","启动成功");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"启动失败");
}

//获取应用程序池列表 等操作
/// <summary>
/// 获取应用程序池->数组
/// </summary>
/// <returns></returns>
public ApplicationPool[] GetApplicationPools()
{
if ((SiteInfo.ServerType != WebServerTypes.IIS6) && (SiteInfo.ServerType != WebServerTypes.IIS7)) return null;
DirectoryEntry directoryEntry = GetDirectoryEntry("IIS://LOCALHOST/W3SVC/AppPools");
if (directoryEntry == null) return null;
List<ApplicationPool> list = new List<ApplicationPool>();
foreach (DirectoryEntry entry2 in directoryEntry.Children)
{
PropertyCollection properties = entry2.Properties;
ApplicationPool pool = new ApplicationPool();
pool.Name = entry2.Name;
list.Add(pool);
}
return list.ToArray();
}
/// <summary>
/// 应用程序池
/// </summary>
public class ApplicationPool
{

/// <summary>
/// 版本
/// </summary>
public string DotNetVersion = "v2.0.50727";
/// <summary>
/// 应用程序池名
/// </summary>
public string Name = "";
}

连接
习惯就好 2012-02-21
  • 打赏
  • 举报
回复
ApplicationPool 在 Microsoft.Web.Administration.dll 中(.NET Framework 3.5)



ApplicationPool[] AppPools = IISHelper.GetApplicationPools();
foreach (ApplicationPool pool in AppPools)
...{
Console.WriteLine(pool.Name);
}


/**//// <summary>
/// 获取应用程序池->数组
/// </summary>
/// <returns></returns>
public ApplicationPool[] GetApplicationPools()
...{
if ((SiteInfo.ServerType != WebServerTypes.IIS6) && (SiteInfo.ServerType != WebServerTypes.IIS7)) return null;
DirectoryEntry directoryEntry = GetDirectoryEntry("IIS://LOCALHOST/W3SVC/AppPools");
if (directoryEntry == null) return null;
List<ApplicationPool> list = new List<ApplicationPool>();
foreach (DirectoryEntry entry2 in directoryEntry.Children)
...{
PropertyCollection properties = entry2.Properties;
ApplicationPool pool = new ApplicationPool();
pool.Name = entry2.Name;
list.Add(pool);
}
return list.ToArray();
}


/**//// <summary>
/// 应用程序池
/// </summary>
public class ApplicationPool
...{

/**//// <summary>
/// 版本
/// </summary>
public string DotNetVersion = "v2.0.50727";
/**//// <summary>
/// 应用程序池名
/// </summary>
public string Name = "";
}



大飞飞虫 2012-02-21
  • 打赏
  • 举报
回复
为神马没人回答呀?
另外读注册表中有信息吗?会不会涉及到WIN7/WIN2008的权限问题?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧