修改web的程序集部分中的值.使用c#配置
本文关键字:使用 配置 web 程序集部 修改 | 更新日期: 2023-09-27 18:02:27
我需要找出一种方法来添加CRUD(创建,读取,更新和删除)支持web中的组件部分。配置文件。
它可能看起来像这样
<system.web>
<compilation defaultLanguage="c#" debug="true" batch="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
</system.web>
我已经试着这样开始了
public bool AssemblyExist(string name)
{
var webConfig = new ExeConfigurationFileMap { ExeConfigFilename = GlobalSettings.FullpathToRoot + "web.config" };
var config = ConfigurationManager.OpenMappedExeConfiguration(webConfig, ConfigurationUserLevel.None);
var assemblies = config.GetSection("system.web");
// return true on match
return assemblies.ElementInformation.Properties.Keys.Equals(name);
}
当然它失败了。
我想要的是一个展示如何在系统中获取值的例子。Web>编译>程序集部分!
任何建议吗?
有一个名为AssemblyInfo的数据类型,其中包含键!
private bool AssemblyExist(string fullName)
{
var config = WebConfigurationManager.OpenWebConfiguration("~");
var compilationSection = (CompilationSection)config.GetSection("system.web/compilation");
return compilationSection.Assemblies.Cast<AssemblyInfo>().Any(assembly => assembly.Assembly == fullName);
}
或者在ubmraco
中使用private bool AssemblyExist(string fullName)
{
var webConfig = new ExeConfigurationFileMap { ExeConfigFilename = GlobalSettings.FullpathToRoot + "web.config" };
var config = ConfigurationManager.OpenMappedExeConfiguration(webConfig, ConfigurationUserLevel.None);
var compilationSection = (CompilationSection)config.GetSection("system.web/compilation");
return compilationSection.Assemblies.Cast<AssemblyInfo>().Any(assembly => assembly.Assembly == fullName);
}
这样称呼
AssemblyExist("System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089")
和添加程序集
private static void AddAssembly(string fullName)
{
var config = WebConfigurationManager.OpenWebConfiguration("~");
var compilationSection = (CompilationSection)config.GetSection("system.web/compilation");
var myAssembly = new AssemblyInfo(fullName);
compilationSection.Assemblies.Add(myAssembly);
config.Save();
}
将其命名为
AddAssembly("System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
Cherio