Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:58:52+00:00 2026-05-23T01:58:52+00:00

I have a custom configuration file in my asp.net website, named urls.config , which

  • 0

I have a custom configuration file in my asp.net website, named urls.config, which contains simple key value, just for redirection purpose, now I want to read this file programmatically and also add values in this file, I am able to use XMLTextReader and XMLDocument to read value from this file, but i am unable to add values in this file.

Any help will be greatly appreciated.
Here is my structure for the configuration file:

<rewriteMaps>  
  <rewriteMap name="StaticRewrites" />  
  <add key="/superstars4012" value="/article.aspx?articleid=4012" />  
  <add key="/superstars4013" value="/article.aspx?articleid=4013" />  
  <add key="/superstars4014" value="/article.aspx?articleid=4014" />  
  <add key="/superstar" value="/article.aspx?articleid=4012" />  
</rewriteMaps>  


XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("urls.config"));
XmlElement element = doc.CreateElement("add");
element.SetAttribute("key", txtAddVanity.Text);
element.SetAttribute("value", "/article.aspx?articleid=4012");
doc.DocumentElement.AppendChild(element);
doc.Save(Server.MapPath("urls.config"));

this works well if the file extension is .xml, but does not when i change it to .config, my requirement is .config, as redirects does not work in .xml

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:58:53+00:00Added an answer on May 23, 2026 at 1:58 am

    As eloquently stated in this msdn post, modifying the web.config file while the application is running is certainly possible (as it is just text, after all) but would be a very bad idea, in that modifying the config file will result in the application being restarted on the server — ending any sessions with current users, and all new visitors seeing an error page until the application is restarted. Certainly not ideal.

    From the look of your code,

    <add key="/superstar" value="/article.aspx?articleid=4012" />  
    

    It appears you are doing url rewriting from a static url to a dynamic query string. There are much better ways of accomplishing this. One is the IIS module “user-friendly urls.” I have very few problems that I couldnt solve using this module.

    Its logic is as follows:

    1. user enters “http://www.domain.com/page-this-or-that
    2. IIS has a regex rule that matches that url pattern and catches the url
    3. the user is directed to http://www.domain.com/page?id=page-this-or-that
    4. You recieve the querystring and store it in a string
    5. You then execute a database call that retrieves and displays the database row with the title “page-this-or-that”

    This would be much easier to maintain, as well as safer for your application and your users.

    -Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom configuration section within web.config file. I'm lingering between: Reading it into
I have modified my web.config file in my asp.net web application so that I
I have a web application with a custom configuration section. That section contains information
We have an ASP.NET MVC 3 web site which isn't working after it's deployed
I have a solution that contains two projects. One project is an ASP.NET Web
I'm helping build an ASP.NET C# application with multiple custom configuration files. We store
I have a chef cookbook which installs nginx and install a custom nginx.conf file.
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom component that I can place in my layout file (XML) for
I developed a website in asp.net and i place the site in online. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.