aspnet读取配置文件

 XmlDocument doc = new XmlDocument();
 doc.Load(Request.PhysicalApplicationPath + "/Advertisingxml/xcimg.config");//读取配置文件


 XmlNode rooturl = doc.SelectSingleNode("configuration/img");//获取节点
 if (rooturl.ChildNodes.Count > 0)
  { 
         Random rdom = new Random();

         int s = rdom.Next(0, rooturl.ChildNodes.Count - 1);//随机抽取图片
         string root = string.Empty;
          if (!Request.ApplicationPath.ToString().Equals("/"))

         {

                   root = Request.ApplicationPath;

         }
            xch.InnerHtml = "<img src='" + root + "/" + rooturl.ChildNodes[s].Attributes["value"].Value + "' style='width:300px; height:72px;' alt='锋象网经历分享'/>";
  }

备注:

1.对少量,灵活,多变,而且保密性比较低的数据建议存储在配置文件中。

2.用.config和.xml存储数据还是有一定的区别,config是配置,.xml是软件内置的网页文件。所以想web.config这类保密性高的数据建议用.config存储。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值