One things that has always been utterly confusing in ASP.NET is the dang Web.Config file. For the beginner to ASP.NET it makes next to no sense and Visual Studio adds a whole bunch of stuff to it that I have no idea what it does. It is also so odd and confusing if I want to do basic config stuff in my application I have no idea how in the world to go about it.
Partly out of necessity and partly to rid myself of not knowing how the web.config works I have been spending time learning about it. I am first starting out with the basics. Getting something to work.
Getting Started
With most things I want to learn I completely bypass the "how" at first and get something basic to work, which is usually a "Hello World". That is what we are going to work on in this post. Lets just see something work. So these are the two objectives:
1) Set a configuration option we can use in our code
2) Allow for debugging our ASP.NET application
Now, we don't "need" a web.config to run basic .aspx pages, but if you want to anything more advanced than a one page site then you will need one.
Web.Config
Here is our web.config that we are going to look at today.
This is really all we need to set a configuration option to access in code and to allow for debugging our application. Please notice that everything is wrapped in:
<configuration>
</configuration>
That is important to note because all your config information should be under the root configuration node.
Custom Application Configuration
Next we have where we will set configuration options.
<appSettings>
<add key="Hello" value="World" />
</appSettings>
In the appSettings is where you will put configuration options that are like global variables to your WHOLE asp.net application. So in this case you will access the Hello key and it will return the world as its value. So the code you would use to access the config options is:
You will use ConfigurationManager object which access all the information in your web.config file. Since the Hello key is in the <appSettings> node then you would use AppSettings collection to access what key value pair you need. In this case accessing hello and it returns world.
Why would you ever need to use this? Well one things comes to mind. You might have a membership system that you want to turn on and off so you could have in the web.config:
<appSettings>
<add key="Membership" value="false" />
</appSettings>
In your code you might have it check to see if it is true or false if true then it displays login stuff for people to register and login if false it doesn't display it. It might look something like:
If(ConfigurationManager.AppSettings["Membership"] == "true")
//display login control
This is just a possibility of something you might want to do.
Debug
<system.web>
<compilation debug="false" />
</system.web>
Here we set whether we want to debug our application or not. I usually set this to yes as I have yet to write a bunch of code with out a bug. All you need to do is to change false to true and you will enable debugging in your asp.net application.
Conclusion
The web.config file is actually a little more simple than it appears once you understand more of what is going on with it. If you take learning it slowly and one little step at a time it is quite possible. I hope to cover a little bit at a time of the web.config as I learn more and more since it is quite important to learn.
Yesterday in the "Coolness of SubSonic" post I had a bit of asp.net markup (as I call it) that would display data in a data list from the data source. It specifically used.
<%# Eval("Name") %>
For a long time I have wondered how that worked I could never seem to figure it out until yesterday. Basically, you have an object that you bind to the data control like a datalist. In the case yesterday it was a Product class Object:

Well in the asp.net markup that we have below:
Notice in the Eval part it uses Name also notice from the product class above there is a name property. What ever property the object has you can use that in the Eval and it will display the data in there that comes from our collection of objects. In this case the Name property of our collection of Product Objects.
I know this wasn't a "cool" post, but it is something I was excited to finally understand so I thought I would post on it to help others understand hopefully.
From my last post
SQL Parameters in C# I mentioned that I wanted to learn an ORM package. Well I took a quick glance at
NHibernate and got overwhelmed and decided to take a look at
SubSonic as I have heard a lot of good things about it. Well I am happy to say I doubt I will EVER do database access by hand ever again if I can help it. As such I figured I would make a code post on some
SubSonic code. I am not really going to explain it just want to show you how easy, cool and simple it is. I'll show the code starting with my .aspx main aspx page code, the code behind then the data access layer code.
I am also including the project I used too. Be sure you have Northwind database.
I suggest you download, install, and start using SubSonic. It is a great framework to help generate and create your DAL. Once you have it I suggest you watch the screencast on the using the Query Tool. If you would like me to explain this code i'd be more than happy to just let me know and I'll make another post.
SubSonicTest.zip (188.54 kb)
Short answer: No.
Here is how I got there and why I think it isn't bad.
First, I want to start off with 2 of my major goals in life then an analogy. Afterwards I will tie it all together with regards to the Microsoft MVP award.
Goals:
Learn everything and help as many people as I can learn what I know. Think about it you know you can't learn everything but you set your goal to learn everything imagine how much you can learn if you fall just short. You will probably learn quite a bit.
Analogy:
If a person is going to run 5 miles no matter what. Is it wrong for him to set a side goal of getting 1000 dollars if it is available. To me no there isn't anything wrong since he is going to run no matter what. (just imagine for a moment strictly running for money is bad)
Now I am sure some of you are going huh about now. Here is how I look at having a goal of earning the MVP award. I am going to help the community no matter what. I have been doing so for 4 years and will continue to do so for as long as I am able. Some of the things I have done and do are:
Blog
Attend DNUG meetings
Speak at DNUG meetings
Work on staff at Conference
Help Organize Dev Conference
Post on forums
Those are some of what I do to help, have done for a while and will continue to do them because I enjoy it.
So, if I am going to do the above in order to obtain my original 2 goals above then I don't see a problem in having a side goal of earning MVP award if it is available. For me the first two goals are most important over all others (within the non-political, non-religious, and non-family context).
Now some have said that the MVP isn't in my control so it isn't a very good goal to have. I have to disagree to an extent. Earning MVP may not totally be in your control, but there are things you can do so that it doesn't go the way of a dream. To me a dream is something that would be nice, but isn't what you are going to pour your heart and soul into doing or getting. Like going to space is a dream for me. It would be nice, but I am not going to spend the time to do it (I'll wait until it is affordable). Compared to that there is an amount of control in earning MVP, by helping the community. Earning the MVP isn't all up to you, but you don't have to keep it in the same realm as going to space.
In the end to me if earning MVP isn't your primary goal then having it as a goal, namely side goal, isn't bad at all. If it is a primary goal then I suggest re-assessing what you are doing and why because that is a lot of work for the chance of it not happening. If the primary goal is helping others in the community and teaching; then by all means a side goal of MVP is not a bad thing.
Please let me know what you think especially if you don't agree with me. Please, let me know how I am wrong if I am.
EDIT: Just wanted to note that I am NOT and MVP, but want to become one.
I just want to say welcome to my new ASP.NET blog. I have been blogging since 2004 over at BuddyLindsey.com, and will continue to. Back then I tried hard to get a blog here, but to no avail. It has been one of my goals to be able to blog here with some of the other great bloggers on the asp.net site.
What I blog about usually is doing beginner content. Things that people normally "assume" other people know I blog about it because often times beginners don't know what people should know. I also like to blog so that I can learn new things because it gives me an avenue to write about what I have learned so I can put into words and text to better understand what is going on. I also like to to receive feedback so please feel free to comment and leave suggestions to help me out.
Just to let you know I will be cross posting my asp.net posts on BuddyLindsey.com and here. Please feel free to read some of my posts on my other blog. Here are some of the higher traffic posts.
TDD Series
Part 1: TDD Test Driven Development for Beginners pt1
Part 2: TDD for Beginners pt2 - Pig Latin
Part 3: TDD for Beginners pt3 - The Application
Part 4: TDD for Beginners pt4 - Unit Tests
XML Series
Part 1: Write to XML File Using C#
Part 2: Reading Data from XML File Using C#
Part 3: Delete Data from XML File Using C#
Others
Hello World of Rhino Mocks
Real World Interfaces in C#
SQL Parameters in C#
Please let me know what you think and if there are any topics you want to know about.
More Posts