web.config中如下面一段代码:
         <forms loginUrl="/admin/login.aspx" protection="All" name=".AdminNameAuth">
           <credentials passwordFormat="Clear">
             <user name="admin" password="10000"/> 
           </credentials>
         </forms>
要在aspx中修改name="admin" password="10000"的值,要怎么做,有没有有具体的例子参考。请大家帮忙,先谢过

解决方案 »

  1.   

    8         public static void WriteWebConfig(string appSettingsName, string newValue)
     9         {
    10             string fileName = HttpContext.Current.Server.MapPath(@"~\Web.config");
    11             XmlDocument xmlDoc = new XmlDocument();
    12             xmlDoc.Load(fileName);
    13             XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
    14             foreach (XmlElement element in topM)
    15             {
    16                 #region 取得目标节点,并赋新值
    17 
    18                 if (element.Name == "appSettings")
    19                 {
    20                     XmlNodeList node = element.ChildNodes;
    21                     if (node.Count > 0)
    22                     {
    23                         foreach (XmlElement el in node)
    24                         {
    25                             if (el.Attributes["key"].Value == appSettingsName)
    26                             {
    27                                 el.Attributes["value"].Value = newValue;
    28                                 xmlDoc.Save(fileName);
    29                                 return;
    30                             }
    31                         }
    32                     }
    33                 }
    34 
    35                 #endregion
    36             }
    37         }
      

  2.   

    参考
    http://blog.csdn.net/hertcloud/archive/2007/03/19/1533474.aspx
      

  3.   

    补充:
           <authentication mode="Forms" > 
             <forms loginUrl="/admin/login.aspx" protection="All" name=".AdminNameAuth">
               <credentials passwordFormat="Clear">
                 <user name="admin" password="10000"/> 
               </credentials>
             </forms>
           </authentication>
      

  4.   

    XmlDocument 和   XmlReader这两个有什么区别啊?,我一直是用后面的那个,希望能指教。
      

  5.   

    楼上的,你用XmlReader怎么做的,告诉我一下啊,先谢谢了
      

  6.   

    不就是修改XML文件么,没办法直接改WEB.CONFIG的,会导致网站重启才能生效
      

  7.   

    KKND2006(人生有两种遗憾:一种是没得到,一种是得到了) 说的有道理
      

  8.   

    KKND2006(人生有两种遗憾:一种是没得到,一种是得到了) 说的有道理