<appSettings>
<add key="DomanName" value="......../Resource/" />
</appSettings>
想读到这里面的 VALUE

解决方案 »

  1.   

    通过ajax读取we.config,再
    var xmlHttp;
        function createXMLHttpRequest()
        {
            if(window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
    异步获取数据
      

  2.   

    当一个xml wen jian ,yong "dom" a!
      

  3.   

    换个思路,后台用个程序中转一下html页面.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>无标题页</title>
    <script type="text/javascript">
    var Ajax = function(){};
    Ajax.prototype = {
    createHttpRequest : function(){
    if(window.ActiveXObject){
    var ver = ["Microsoft.XMLHTTP","MSXML.XMLHTTP"];
    for(var i=0; i<ver.length; i++){
    try{
    return new window.ActiveXObject(ver[i]);
    }catch(e){}
    }
    }else{
    try{
    return new XMLHttpRequest();
    }catch(e){}
    }
    alert("Failure to create HttpRequest!");
    },

    get : function(url, async, fnCallBack){
    var xmlHttp = this.createHttpRequest();
    xmlHttp.open("GET", url, async); xmlHttp.onreadystatechange = function(){
    if(xmlHttp.readyState == 4 ){
    if(xmlHttp.status == 200){
    fnCallBack(xmlHttp.responseText);
    }else{
    fnCallBack(null);
    }
    }
    };
    xmlHttp.setRequestHeader("If-Modified-Since","0");
    xmlHttp.send(null);
    }
    };window.onload = function(){
        var ajax = new Ajax();
        ajax.get("webConfig.ashx", true, function(data){
            alert(data);
        });
    };
    </script>
    </head>
    <body></body>
    </html>
    后面处理程序 webConfig.ashx<%@ WebHandler Language="C#" Class="webConfig" %>using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.Configuration;
    using System.Xml;public class webConfig : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/html";
            context.Response.Write(getWebConfig());
        }
     
        public string getWebConfig(){
            string result = "not found!";
            string strFileName = HttpContext.Current.Server.MapPath(".") + @"\Web.config";
            XmlDocument doc = new XmlDocument();
            doc.Load(strFileName);        XmlNodeList appSetting = doc.DocumentElement.GetElementsByTagName("appSettings");        if(appSetting.Count > 0){
                
                XmlNodeList add = appSetting[0].ChildNodes;
                for(int i=0; i<add.Count; i++){
                    XmlNode el= add.Item(i);
                    if(el.NodeType == XmlNodeType.Element && el.Attributes["key"].Value == "DomanName"){
                        result = el.Attributes["value"].Value;
                        break;
                    }
                }
            }
            return result;
        }
        public bool IsReusable {
            get {
                return false;
            }
        }}
      

  4.   


    <%@ WebHandler Language="C#" Class="webConfig" %>using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.Configuration;
    using System.Xml;public class webConfig : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/html";
            context.Response.Write(getWebConfig());
        }
     
        public string getWebConfig(){
            string result = "not found!";
            string strFileName = HttpContext.Current.Server.MapPath(".") + @"\Web.config";
            XmlDocument doc = new XmlDocument();
            doc.Load(strFileName);        XmlNodeList appSetting = doc.DocumentElement.GetElementsByTagName("appSettings");        if(appSetting.Count > 0){
                
                XmlNodeList add = appSetting[0].ChildNodes;
                for(int i=0; i<add.Count; i++){
                    XmlNode el= add.Item(i);
                    if(el.NodeType == XmlNodeType.Element && el.Attributes["key"].Value == "DomanName"){
                        result = el.Attributes["value"].Value;
                        break;
                    }
                }
            }
            return result;
        }
        public bool IsReusable {
            get {
                return false;
            }
        }}
      

  5.   

    web.config只有让后台才能读取吧,然后用ajax从后台读取
    支持8L
      

  6.   

    只能用后台读取,然后用ajax传回来
    web.config是不允许通过http这样的路径访问的
      

  7.   

    建议按照 8 楼 Free_Wind22 的思路进行读取