Change URL Rewrite Rule in Web.Config from Code C#

后端 未结 3 1912
轮回少年
轮回少年 2021-01-02 08:49

I want to modify rewrite rule from C# code. Url Rewrite rule is resides in web.config file.


    
               


        
3条回答
  •  暖寄归人
    2021-01-02 09:26

    I change value for connectionString in my web.config website with this code :

    May be this example can help you (just change the value connectionString by system.webServer and add by rules etc.. Please tell me if it works for you

    XmlDocument myXmlDocument = new XmlDocument();
    myXmlDocument.Load("../myPath/web.config");
    foreach (XmlNode node in myXmlDocument["configuration"]["connectionStrings"])
    {
        if (node.Name == "add")
        {
            if (node.Attributes.GetNamedItem("name").Value == "SCI2ConnectionString")
            {
                node.Attributes.GetNamedItem("connectionString").Value = "new value";
            }
        }
    }
    

提交回复
热议问题