Web.Config Basics pt 1

by percent20 2/6/2008 11:59:00 AM

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.

CropperCapture[45]

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:

CropperCapture[48]

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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.NET | ASP.NET

Eval in DataList, DataGrid, and Repeater

by percent20 1/24/2008 2:09:00 PM

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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | ASP.NET

Best quote about Microsoft

by percent20 10/15/2006 12:58:00 PM

Today I helped run Tulsa Tech Fest, and I must say it was awesome.  During the event I went to 2 of Caleb Jenkins’ presentations one over ajax/atlas and the other over WPF, which r0×0rz.

While in the Atlas/Ajax presentation Caleb had the greatest quote about Microsoft I have ever heard.

“Microsoft doesn’t create cool stuff, they enable everyone else to create cool stuff.”

Now, to defend Caleb it was in the context of Atlas itself and how it is extendable. However, the quote is so true I mean google wouldn’t be where they are today if it wasn’t for Microsoft.

BLASPHEMY, is what some of you are yelling.

Here is why though.  Microsoft created the ActiveX object that allows AJAX to exist.  From ajax Google maps, gmail and many other services exist that heavily use the technology and has helped to put google on the map.

So remember Microsoft helps you become Google.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

ASP.NET | Microsoft

My New Idea

by percent20 9/29/2006 12:53:00 PM

I frequently come up with awesome ideas for web based applications.  Most of them I don’t share with people I just write them down and keep them so I can maybe do them at a later date and possible earn a bit of cash off of them.  In all I have about 20 ideas that still have yet to be done on the internet, most aren’t hard just takes some thought and time.  However, this new idea i want to share because I want to see it, and I don’t care who does it.  I will probably do it someday just not right now because it definatly is beyond my skill level.

So the idea is basically a Web Based IDE for ASP.NET and any type of .NET app that can be made. With the recent advent of Atlas for asp.net there can be a lot of things done asynchronisly you can have a lot of IDE type things that can happen. I am more invisioning a Visual Studio type IDE with almost as many functions that can be done through a web page, which is quite a bit if you have seeen http://local.live.com.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

ASP.NET | Awesome Stuff

Mono Presentation

by percent20 1/22/2006 7:50:00 AM

Well I have been working pretty diligantly today on my mono presentation for next monday. I must say though if I pull this off by some miracle it will be awesome. I am really likeing what has come together. I will also have a nice treat for the people attending the presentation on the 30th from a new friend in Dallas Joseph Hill.

I have used several live distrobutions of linux in the past to play with mono the first one I used was monoppix. Well since it was a great resource that had video tutorials, woot, then I wanted to add it so I doubled checked the site the old fashion way I tried to go there. Well guess what it isn’t there anymore. Hmm, that stinks it was good, but I have good news I save a bunch of… I mean there is Mono-Live which is the official live cd for mono. Now I must say this thing is awesome. Every mono program works like a charm. Usually I have to tweak and play and massage things to work, but not on Mono-Live it just worked which impressed me.

So go check it out. Mono-Live.

That is pretty much it for now need to get back to work I have a lot to do hope to see anyone local reading this at the next meeting.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

.NET | ASP.NET | Mono | Open Source

Closing the deal can be painful

by percent20 12/11/2005 7:38:00 AM

My biggest problem for a long time was actually finishing a project. Well I spent a while working on a site on my own and i finally finished it. While it isn’t so great to look at it is fully functioning with news and suggestions and is backed by a database. The biggest problem though that I noticed was making the different parts wasn’t to hard just took some dedication to it. No the hard part was bringing it all together in a nice format that is unified. It wasn’t diffucult just very time consuming and that is what made it hard.

So I can now say that i have actually made something and finished it. The funnything is I have nowhere to host it and even if I did I don’t think I would because it doesn’t look that great visually and beleive it or not a lot of people judge a site by its sex appeal that are non technical.

I did the site’s visuals without master pages which is cool I wanted to see what it would be like to do so. I now see the benifit for sure of master pages. I know a speak a lot about master pages, but it is an awesome feature that makes things very very nice.

Oh, yeah I hope this makes some sense I have had a searious cold that last two days and have been out of it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ASP.NET | Personal

Quick note about Master Pages

by percent20 11/30/2005 5:01:00 PM

When you read most tutorials about master pages they tell you that you just need the at directive at the top to declare its mater page and then only asp.net content in the rest well that gets confusing.

What needs to be said is you need the @ directive stating the master page to use, and you don’t need any html. However, you can use HTML and css and other things inside of the content page. You just don’t need the html that sets up the page such as: 

<html>
<head>
<title></title>
</head>
<body>
</body>
</html>

You no longer need that. It leaves you free to insert pure content of anytype without make sure that those setup tags are in your page.

Hope that helps someone.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

Master Pages vs. CSS

by percent20 11/29/2005 7:26:00 AM

I must say that master pages are really really cool. At first I was concerned that Master Pages was going to force everything that you did to be in tables thus taking CSS out of the picture. I was mainly concerned about this because I can see the benefits that CSS can offer to web developers and want to use this really cool and useful technology.

When I first saw Master Pages being used I would look at the code and see almost nothing but tables being used for positioning of objects and it was annoying because after all I want to use CSS. So I proceeded to start and learn CSS anyway hoping that I could just override the default output that Master Pages used.

Well I have learned quite a bit about CSS now, basically I am confident with it, and just took a look at Master Pages. I must say I was impressed by them the blew me away with the possibilities. I am still learning them so some of the problems I forsee are probably solved. Let me first explain a little bit about master pages first.

Master Pages is a new technology in ASP.NET 2.0 that allows for a unified look and feel of a website without having to go in and customize individual pages, which can take up hours. With master pages you make a sing master page that has the look and feel you want across all pages such as the most common things menu, banner, and footer. Now user controls reduced the time it took to do this significantly, but Master Pages is just where it is at.

Now CSS offers pretty much the same thing. You make up your classes for your divs with positioning font information yada yada yada. Now Master Pages makes it faster than CSS, but if it outputs to tables, then where are the web standards? This was my big worry. I want to make standards compliant websites using ASP.NET.

Well here is the cool part. You can use CSS to do the layouts on the Master Page. In fact Master Pages compliments CSS and vice versa. You now only have to make the CSS file, and apply all the classes and ids to one file instead of 20. Now tell me that is not awesome.

What does this mean?

Well it increases the possibilities of standards compliant ASP.NET websites. It allows for less time in development because now you can focus more on the code that is important instead of menial looks. You can now write the whole backend for that amazon.com clone and don’t have to worry about the useless front end.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

.NET | ASP.NET | Awesome Stuff | Programming

CSS and ASP.NET 2.0

by percent20 11/21/2005 7:24:00 AM

Ok, Most of the posts from now on will be about ASP.NET 2.0. I must say though I didn’t really expect to switch so fast. I really liked 1.1, sort of, and was comfortable with it. So I though I would be forced into 2.0, but nope I am loving it. So rarely will I post on 1.1 unless I have a project that requires it, like under Linux. So that is to let you know what is going on there.

So lately I have been reading up on CSS and some of the virtues of it and am really impressed by CSS. Once you play with it for a while you get comfortable with it and can actually start doing interesting things with it. Now I am sure what I am doing now for integrating it into ASP.NET 2.0 is just hacking it in there, but hey it works.

One of the easiest ways to implement it in 2.0 is with the DataList, because it is all that i have tried so far. When you bind the DataList, which is super easy now, it automatically creates the labels and binds data to it no more having to go in by hand to do that. Well all you have to do to use CSS on it is open up the HTML add div apply an id from the CSS file and voila done it comes out pretty.

Now why would you want to do that instead of just applying font properties?

Well now to edit all I have to do is edit the CSS file. It will cut my maintenance time down by quite a bit. A book I suggest is the Zen Garden CSS book, or the site. I wish I had taken my own advice, once again, a long time ago and learned CSS.

If you don’t know CSS and are a web developer either professionally or as a hobbyist I suggest you learn it right a way. Once you get past the learning curve it makes life more bearable.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ASP.NET

MSDN Launch party

by percent20 11/17/2005 7:19:00 AM

Well I went to the MSDN launch party yesterday for SQL Server 2005 and Visual Studio 2005 and I must say WOW.

It was awesome. The demos were incredible it was absolutely amazing some of the things that were show. Like the building of a complete data driven website with the capabilities of users logging in, registering, and personal preferences without a single line of code. That to me was amazing. I honestly can’t wait to get started with ASP.NET 2.0. Actually, I should be starting this week sometime with a redesign of Lhand.com.

As part of the bonus of going to the launch party I got two cool pieces of software, Visual Studio 2005 and SQL Server 2005. Both are the coolest products in the world, and retail together at 6300 dollars. That, my friends is a lot of money. Not to mention the Resource DVD they gave away with 8 gig of content for learning these new products. I am seeing a lot of cool things coming from having these new products. I can’t wait to get started, especially figuring out Atlas (AJAX), and RSS. From what I understand both are super easy to implement in ASP.NET 2.0

Well need to get to work reading up on this stuff so until next time. Happy coding

Buddy Lindsey

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

.NET | ASP.NET | Awesome Stuff | Microsoft | Sql Server | Programming

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen


My Flare

AddThis Feed Button

National Blog Posting Month

Eagle Scout

I'm Test Driven

[Reserved for MVP status I want to earn]

View Buddy Lindsey's profile on LinkedIn

Twitter



Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in