C# 为什么控制器不去创建函数?
我在单独的文件中定义了一些custome部分,但是当我调用C# 为什么控制器不去创建函数?,c#,asp.net,web-config,C#,Asp.net,Web Config,我在单独的文件中定义了一些custome部分,但是当我调用 ConfigurationManager.GetSection("Group/Group1/screen1") 控制器不去创建方法,上面的代码返回null,怎么了?少了什么 web.Config: 我认为custom.config应该从Group1元素开始,而不是Group元素,或者configSource应该应用于组。无论哪种方式,引用的配置文件的根元素都应该与应用configSource的元素类型相同 因此,听起来您希望web.c
ConfigurationManager.GetSection("Group/Group1/screen1")
控制器不去创建方法,上面的代码返回null,怎么了?少了什么
web.Config:
我认为custom.config应该从Group1元素开始,而不是Group元素,或者configSource应该应用于组。无论哪种方式,引用的配置文件的根元素都应该与应用configSource的元素类型相同 因此,听起来您希望web.config中的内容是: 那么place1.config的根元素必须是:
如果我为每个组创建单独的配置group1,group2,。。然后它工作,但我想要一个自定义配置,所以我添加了一个根。根据您的建议,如果我删除组元素,它将抛出运行时错误配置文件的格式不正确。@JeevanBhatt-我没有建议删除组元素。不过我已经更新了我的答案。
<configSections>
<sectionGroup name="Group">
<section name="Group1" type="Handler"
allowLocation="true"
allowDefinition="Everywhere">
</section>
</sectionGroup>
</configSections>
<Group>
<Group1 configSource="folder1\custom.config" />
</Group>
<?xml version="1.0"?>
<Group>
<Group1>
<Screen1>
<Property1>0</Property1>
<Property2>1</Property2>
</Screen1>
<Screen2>
<Property1>1</Property1>
<Property2>Create</Property2>
</Screen2>
</Group1>
<Group2>
<Screen1>
<Property1>0</Property1>
<Property2>1</Property2>
</Screen1>
<Screen2>
<Property1>1</Property1>
<Property2>Create</Property2>
</Screen2>
</Group2>
</Group>
public class Handler: IConfigurationSectionHandler
{
public object Create(object parent, object configContext, XmlNode section)
{
**debugger**
// Some processing
// return object
}
}
<Group configSource="folder1\custom.config" />
<Spargle configSource="place1.config" />
<?xml version="1.0"?>
<Spargle>
<Floom/>
</Spargle>