您的位置:首页 > 编程语言 > C#

c#中webconfig的自定义方法

2015-05-11 11:16 176 查看
1.在webconfig中添加

<configSections>
<section name="picLink" type="System.Configuration.NameValueSectionHandler"/>   </configSections>
<picLink>
<add key="link" value="http://www.auxun.cn/"></add>
</picLink>


2.新建一个cs文件

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)

@using PPP.Code
<img src="@picLinkClass.getPiclink()local/picfolder/no.jpg" style="height:100%">
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: