首先在web.config中的 configSections里添加定义你的section
<configSections>
<section name="picLink" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
然后在configuration中添加你的namevalue项
<picLink>
<add key="link" value="http://www.qnwcn.com/"></add>
</picLink>
最后的调用方法为
using System.Configuration;
using System.Collections.Specialized;
namespace PPP.Code
{
public static class picLinkClass
{
public static string getPiclink(){
NameValueCollection postinfo = (NameValueCollection)ConfigurationManager.GetSection("picLink");
return postinfo["link"];
}
}
}
在下一步你就可以在cshtml或cs里使用了
@using PPP.Code
<ul>
<li>@picLinkClass.getPiclink()</li>
</ul>
本文介绍如何在ASP.NET应用程序中通过Web.config文件配置自定义section,并提供了一个具体的示例,展示了如何设置和获取配置项。

1535

被折叠的 条评论
为什么被折叠?



