ASP.NET Developer Notes

Ryan Garaygay's ASP.NET notes online

Hand Editing Web.Config or not

I've come across a number of issues in the past where the cause of the issue is that someone hand edited the web.config and resulted to a not well formed XML (missing tags, unclosed quotes et al).

The recommended way of doing it is to minimize these issues is to use the ASP.NET Configuration Settings Dialog which is available to IIS (not sure if there is a stand alone executable for this). Here are simple steps to do it.

1. Open IIS

2. Right Click on target site/virtual directory and select Properties

 

3. The Properties dialog should show up. Select ASP.NET tab.

 

4. At the ASP.NET tab, you should see and click Edit Configuration. (if you're opening Properties of a website, you should also see an "Edit Global Configuration" button which corresponds to the machine wide web.config). Doing so should display the Configuration Settings Dialog

 

5. Make your modifications without fear of unclosed quotes whatsoever. You could likely still mess up some settings but I can assure you that it would be easier to do when you're manually hand editing the file.

 

Also note that when adding a web.config in Visual Studio (using Add New Item) you will get a comment somewhere at the top stating: 

<!--

    Note: As an alternative to hand editing this file you can use the

    web admin tool to configure settings for your application. Use

    the Website->Asp.Net Configuration option in Visual Studio.

    A full list of settings and comments can be found in

    machine.config.comments usually located in

    \Windows\Microsoft.Net\Framework\v2.x\Config

-->


The "Website->Asp.Net Configuration option in Visual Studio" mentioned are items in the toolbar and appears if you have the website project (or its files) open/selected (see image below)

This is also a recommended way of doing it for web site projects (not available in Web Application Projects).

Editing web.config is likely inevitable for development but as much as possible I would recommend not hand-edit them unless you (or others in the team) really have to (especially for those with not much experience with XML/HTML - it is trivial but could minimize some headaches)

UPDATE: I have updated the post title from "Hand Editing web.config, not" to "Hand Editing web.config or not" since it seems to make a big difference. I personally hand edit most if not all web.config I work with but this is merely an alternative based on experience where there are actually people out there guilty of messing the xml for a lot of reasons. Being an alternative it may or may not be best for all situations. Also, as a starting/budding developer it is sometimes (if not all the times) best to learn from mistakes so I am in no way against hand editing of files. However like gurus out there, be careful in doing as it would probably hurt more than missing something in HTML. Furthermore for those not yet confident enough to mess up with config manually this might be for you. Although again it's best to learn from mistakes if you can afford to do so since you will surely remember it more. :)

Posted: Apr 22 2008, 09:49 AM by ryangaraygay | with 37 comment(s)
Filed under:

Comments

Dave said:

Exactly how does a web.config make it through at least 2 other environments before getting to your production without noticing a problem? Problem doesn't sound like hand editing rather editing files directly in production.

# April 22, 2008 12:28 AM

ryangaraygay said:

So far I've only seen this in non-production environments but in cases where there is only one other environment than production, it might still be possible.

Your right. But more likely both, 1.) editing files directly in production and 2) hand-editing them. Both of which could cause a headache on its own.

As mentioned, maybe not be an issue to experienced developers and those following good development processes but I won't be surprised if a number of those doing development ran into to this one way or another. :)

# April 22, 2008 4:56 AM

pho said:

and... does this work if you make custom configuration handlers, too? or only for basic string appSettings

# April 22, 2008 7:17 AM

Peter said:

I always hand-edit my web.configs. A few days ago I tried to move a site that ran fine in IIS6 to IIS7 under Vista (I hope it's fixed in the real IIS7). When I used the tool to edit my web.config, guess what... it corrupted the file. It didn't leave any open tags, but it didn't parse it well and duplicated some branches which gave me runtime errors. Took me a while to figure out, originally I didn't think the tool would mess up the file... there goes your advice.

# April 22, 2008 8:34 AM

ryangaraygay said:

@pho: I'm not sure what you're referring to with custom configuration handlers but if it's customer configuration sections, I don't think it would be able to handle that. In addition to appsettings though, you could also specify settings for connectionstrings, authorization, authentication, state management etc. The later (Website -> ASP.NET Configuration) also enables you to manage your membership, role providers.

@Peter: thanks for the feedback. I haven't had the chance to try it out with IIS7 (haven't worked with Vista at all in fact) but thanks for the significant observations.

Most of the time I personally hand edit the config files too but as mentioned tools like these are made to minimize errors in addition to ease of configuration. If they mess up then it sucks and should be fixed. It might be a good idea (not to mention highly appreciated by the community) if you could provide such information to say Microsoft Connect too. When I get a chance to try it out, I'll be sure to update. :)

# April 22, 2008 11:30 AM

.NET Developer Notes said:

Not Hand editing web.config

# April 22, 2008 11:36 AM

mikedopp said:

I constantly hand edit my web.config... What? My site is down? Crap gotta go!

# April 23, 2008 11:29 AM

propecia said:

I want to say - thank you for this!

# June 6, 2009 3:40 PM

alhadass said:

AWSOMENESS!!!!!

thank for helping a brotha out dude!

# August 20, 2009 10:03 AM

turbo said:

BEST MAAAAN :D THANK YOU

# September 15, 2009 12:25 PM

hotmom said:

Thanks so much! I've looked everywhere for this! You're amazing!

# September 27, 2009 10:02 AM

Aron said:

# March 10, 2010 7:39 AM

soundtrack said:

It is a pity, that I can not participate in discussion now. I do not own the necessary information. But this theme me very much interests.

# March 13, 2010 1:08 PM

Dominic said:

<a href= powerlinejcpenneybenefitsemployeeresource.firepuffed.in >powerline jcpenney benefits emp

# April 6, 2010 6:21 PM

авто said:

I consider, that you commit an error. I can defend the position

# April 13, 2010 8:45 AM

Halo said:

# April 29, 2010 8:11 PM

Neo said:

<a href= http://blackm

# April 29, 2010 10:06 PM

Neo said:

# May 22, 2010 2:58 PM

Arnie said:

<a href= albertomartinezalpoharlem.likedaled.in >alberto martinez alpo harlem</a>

# May 26, 2010 1:33 PM

Halo said:

<a href= gangsterjue.doggooded.in >gangster jue</a>  

# June 11, 2010 11:01 AM

Diesel said:

<a href= angelabridgesnakedclips.likegooded.in >angela bridges naked clips</a>  

# June 28, 2010 4:10 PM

AnitotrartMaw said:

I enjoyed reading your blog. Keep it that way.

# August 22, 2010 3:55 AM

TypeTalaneria said:

The restaurants list with thousands of restaurants reviewed by visitors. restaurants-us.com/.../99223

# October 3, 2010 1:50 AM

How to Make Dog Clothes said:

I am speechless. This can be a wonderful blog site and really participating as well. Excellent function! That is not truly much approaching from an beginner author like me, but it is all I could think soon after enjoying your posts. Great grammar and vocabulary. Not like other blogs. You seriously know what you're speaking about very. So very much that you just produced me wish to investigate extra. Your blog has grow to be a stepping stone for me, my friend. Give thanks to you for the articulate journey. I really loved the 27 posts that I have read so far.

--------------------------------------------

my website is  

http://shirtsshirt.net

Also welcome you!

# November 22, 2010 10:53 PM

ipad app download said:

Sharp tools make good work.

-----------------------------------

# December 21, 2010 11:52 PM

ipad reviews feb 2010 said:

Gratitude is the sign of noble souls.

-----------------------------------

# December 24, 2010 12:18 PM

ipad app reviews said:

-----------------------------------------------------------

found your internet site on del.icio.us these days and genuinely liked it.!! i bookmarked it and will be back again to check it out some a lot more later .<br>.

# January 2, 2011 3:42 PM

best ipad case said:

-----------------------------------------------------------

I like to take breaks in the course of the day and browse by way of some blogs to find out what others are saying. This blog appeared in my searches and I couldn't assist but clicking on it. I am pleased I did simply because it absolutely was a quite enjoyable read.

# January 7, 2011 4:34 PM

best ipad stand said:

-----------------------------------------------------------

A mutual friend stated I should come consider a look at your internet site. Happy I clicked on the link! I like how you truly concentrate and get on the bottom line but can you operate through that final component again? Just a little?

# January 11, 2011 4:29 PM

camcorders reviews said:

found your site on del.icio.us right now and seriously liked it.! i bookmarked it and will be again to check it out some far more later !.

--------------------------------------------------------------------  

I have a <a href="onlytopreviews.com/">toaster oven reviews</a> Website,i love him.Mania !You are welcome to look!

# January 16, 2011 2:03 PM

ChetteEresy said:

Directory of restaurants organized by states   <a href="restaurants-us.com/.../">Luke%27s Italian Beef</a>

# February 10, 2011 8:51 AM

Pizza said:

Modern pizza originated in Italy, although the style favored by Americans is more a friend than a relative of the traditional Neapolitan pie.

Sometimes too perfectly, as a 1950s Atlanta restaurateur discovered when he added pizza to his menu and immediately attracted hordes of Georgia Tech students who would congregate around a single pie and linger for hours.

# March 19, 2011 8:42 AM

generic said:

Surprisingly! It is like you understand my mind! You seem to know so much about this, just like you wrote the book in it or something. I think that you can do with some pics to drive the content home a bit, but other than that, this is informative blog post. A good read. I’ll definitely revisit again.

# March 26, 2011 1:25 AM

family travel said:

http://www.familytravel.biz

Surprisingly! It is like you understand my mind! You seem to know so much about this, just like you wrote the book in it or something. I think that you can do with some pics to drive the content home a bit, but other than that, this is informative blog post. A good read. I’ll definitely revisit again.

# June 14, 2011 7:44 AM

Carylon Gorham said:

Strange, your page shows up having a red hue to it, what color is the main color on your website?

# July 1, 2011 3:40 AM

Jennell Gallegoz said:

Maybe you have thinking about adding a bit a lot more than just your thoughts? I'm talking about, what you say is important and every thing. But its got no punch, no pop! Maybe in the event you added a pic or two, a video? You could have such a more effective blog in the event you let people SEE what youre talking about rather than just reading it.

# July 6, 2011 2:57 AM

Hero said:

<a href= accident-car-rinn.abatofmaluku.in >accident car

# December 4, 2011 12:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)