自定义configSections时,这样的格式如何写?

zhao8848jun 2012-03-20 04:03:42
<outboundRules>
<!--新闻频道-->
<rule name="NEWS_EXCLUSIVEREPORT">
<!--独家报道-->
<match filterByTags="A, Area" pattern="^(.*/)news/list\.aspx\?Id=5360" />
<action type="Rewrite" value="/shtml/news/EXCLUSIVEREPORT" />
</rule>
<rule name="NEWS_STAR">
<!--明星-->
<match filterByTags="A, Area" pattern="^(.*/)news/list\.aspx\?Id=4642" />
<action type="Rewrite" value="/shtml/news/STAR" />
</rule>
</outboundRules>

// Define a custom section containing a simple element and a collection of the same element.
// It uses two custom types: UrlsCollection and UrlsConfigElement.
public class UrlsConfig
{
public static UrlsSection GetConfig()
{
return (UrlsSection)System.Configuration.ConfigurationManager.GetSection("CustomConfiguration");
}

}


public class UrlsSection : ConfigurationSection
{
[ConfigurationProperty("urls",IsDefaultCollection = false)]
public UrlsCollection Urls
{
get
{
return (UrlsCollection)this["urls"];
}
}
}
//
//中间如何衔接……?
//
// Define the UrlConfigElementMatch.
public class UrlConfigElementMatch : ConfigurationElement
{
[ConfigurationProperty("filterByTags", IsRequired = true)]
public string filterByTags
{
get
{
return (string)this["filterByTags"];
}
set
{
this["filterByTags"] = value;
}
}

[ConfigurationProperty("pattern", IsRequired = true)]
public string pattern
{
get
{
return (string)this["pattern"];
}
set
{
this["pattern"] = value;
}
}
}
// Define the UrlConfigElementaction.
public class UrlConfigElementAction : ConfigurationElement
{


[ConfigurationProperty("type", IsRequired = true)]
public string type
{
get
{
return (string)this["type"];
}
set
{
this["type"] = value;
}
}

[ConfigurationProperty("value", IsRequired = true)]
public string value
{
get
{
return (string)this["value"];
}
set
{
this["value"] = value;
}
}
}
...全文
46 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhao8848jun 2012-07-04
  • 打赏
  • 举报
回复
没人用过这方面吗
配置文件概述: 应用程序配置文件是标准的XML 文件 XML 标记和属性是区分大小的 它是可以 按需要更改的 开发人员可以使用配置文件来更改设置 而不必重编译应用程序 配置 文件的根节点是configuration 我们经常访问的是appSettings 它是由 Net 预定义配置 节 我们经常使用的配置文件的架构是象下面的形式 先大概有个印象 通过后面的实 例会有一个比较清楚的认识 下面的“配置节”可以理解为进行配置一个XML 的节点 常见配置文件模式: <configuration> <configSections> 配置节声明区域 包含配置节和命名空间声明 <section> 配置节声明 <sectionGroup> 定义配置节组 <section> 配置节组中的配置节声明 <appSettings> 预定义配置节 <Custom element for configuration section> 配置节设置区域 2 只有appSettings 节的配置文件及访问方法 下面是一个最常见的应用程序配置文件的例子 只有appSettings 节 < xml version "1 0" encoding "utf 8" > <configuration> <appSettings> <add key "connectionstring" value "User ID sa;Data Source ;Password ;Initial C atalog test;Provider SQLOLEDB 1;" > <add key "TemplatePATH" value "Template" > < appSettings> < configuration> 下面来看看这样的配置文件如何方法 string connectionString ConfigurationSettings AppSettings["connectionstring"]; 使用ConfigurationSettings 类的静态属性AppSettings 就可以直接方法配置文件中的配置 信息 这个属性的类型是NameValueCollection 3 自定义配置文件 3 1 自定义配置节 一个用户自定义的配置节 在配置文件中分为两部分:一是在<configSections>< confi gSections>配置节中声明配置节(上面配置文件模式中的“<section>”) 另外是在<confi gSections>< configSections >之后设置配置节(上面配置文件模式中的“<Custom eleme nt for configuration section>”) 有点类似一个变量先声明 后使用一样 声明一个配 置文件的语句如下: <section name " " type " " > <section>:声明新配置节 即可创建新配置节 P> name:自定义配置节的名称 type:自定义配置节的类型 主要包括System Configuration SingleTagSectionHandler S ystem Configuration DictionarySectionHandler System Configuration NameValueSectionHa ndler 不同的type 不但设置配置节的方式不一样 最后访问配置文件的操作上也有差异 下面 我们就举一个配置文件的例子 让它包含这三个不同的type < xml version "1 0" encoding "utf 8" > <configuration> <configSections> <section name "Test1" type "System Configuration SingleTagSectionHandler" > <section name "Test2" type "System

62,047

社区成员

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

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

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

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