ASP.NET Best Practices (RSS)

ASP.NET Best Practices

Creating a Base Page Class? Read this First!

The ASP.NET Page Object Model

One Day in the Life of an ASP.NET Web Page

Dino Esposito
Wintellect

August, 2003

Applies to:Microsoft® ASP.NET

Summary: Learn about the eventing model built around ASP.NET Web pages and the various stages that a Web page experiences on its way to HTML. The ASP.NET HTTP runtime governs the pipeline of objects that transform the requested URL into a living instance of a page class first, and into plain HTML text next. Discover the events that characterize the lifecycle of a page and how control and page authors can intervene to alter the standard behavior. (6 printed pages)

http://msdn.microsoft.com/asp.net/?pull=/library/en-us/dnaspp/html/aspnet-pageobjectmodel.asp#aspnet-pageobjectmodel_topic2

Web Services Tip: When to Use and When not to Use

This is a very simple tip and a rule that you should live by MOST of the time. Of course a situation always arises when you need to do something that is not recommend, but in general this rule should be followed:

When to Use XML Web Services

Application to Application Communication

When not to Use XML Web Services

Intra-Application Communication

That's it, that's the tip. It may seem obvious, but I've seen XML Web Services used in the wrong way more than once so I know it's not!

Until next time!

More Information on Web Services:

http://msdn.microsoft.com/webservices/default.aspx
http://www.dotnetjunkies.com/quickstart/aspplus/
http://www.dotnetjunkies.com/tutorial/default.aspx?tid=6
http://www.dotnetjunkies.com/Search/?exSearchPhrase=Web%20Services

Solution Design (Class Structure)

This really isn't a tip, more of a peeve I have. I hate when I pick up someone elses solution and find that there are multiple classes contained in one code file. It is uterly annoying and difficult to find things. I suggest creating a seperate file for each class and name you code files the same as your class definitions. Additionally, create a file structure which corresponds with your namespace definitions.

Tip: If you happen upon a solution where you're having a tough time finding things use the Visual Studio.NET's object explorer:

  1. Hit Ctrl+Alt+J, this will open up the solution in the object explorer.
  2. Now you have a treeview look at your project's namespaces
  3. Drill down to a class and select it
  4. In the right pane right-click on a method name and click "Go to Definition" and you're magically taken to the projects class to the line where that method is defined.

Now for some feedback from you:

Question:  In a logical 3-tier solution how do you define you project hierarchy? Do you keep everything in one project, do you have multiple projects and if so how do you name them. Do you have a well defined folder hierarchy within each project etc. I'll release my hierarchy I typically use after I see what others use. Oh, and why do you choose the way you do it? Is it something you learned or something you developed?

The .NET Pet Shop Sample Application Version 3.0

We just put up version 3.0 of Microsoft's answer to Suns Pet Shop "Blueprint" application. You can find a running version of the sample application here: http://sampleapps.dotnetjunkies.com/MSPetShop/ - On the default page you'll find links to where you can download the application itself with FULL source code. Also, you'll find benchmarks and performance tests of each version (.NET and J2EE).

Do you think it would be a good idea to start discussion forums for these types of applicaitons???

Let me know!

Enjoy!

The First of Many Posts

I just started a new category for my blog named ASP.NET Best Practices. As I stated in another entry I'm putting together a bible of best practices for ASP.NET development. Until it's finished I'm going to be posting a new tip everyday. After it's finished I'll post the document and it will become a living document. If you have a tip respond to one of my tips and I'll add it. Now some of these tips are pretty obvious, but that is exactly why I'm keeping them in. Because they're so obvious they're often overlooked.

General Coding Tips

Use Code Regions: When using Visual Studio.NET or Visual Studio.NET 2003 you can specify code regions. Code regions are basically blocks of code that you can collapse within the Visual Studio IDE. What code regions enable you to do is group related pieces of code together which makes things easier to find. For instance, I typically will group all my properties for a class within a Properties code region.

The way you specifiy a region is a little different between C# and VB. Let's take a look:

Visual Basic .NET

#Region " P R O P E R T I E S "

Public MyProp As String

#End Region

C#

#region P R O P E R T I E S

public string MyProp;

#endregion

There are a couple rules to using Regions.

1.) Regions must have a starting and ending directive
2.) They can be nested
3.) They can't overlap other block statements