Developing ASP.NET Web Applications

In this second part of a three-part series on ASP.Net web programming, you'll learn how state is handled in ASP.Net web applications, the components of the .NET framework, and more. This article is excerpted from chapter one of Murach's ASP.NET 3.5 Web Programming with VB 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774472).

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
June 23, 2009
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

How state is handled in ASP.NET applications

Although it isn’t apparent in the previous figure, an application ends after it generates a web page. That means that the current status of any data maintained by the application, such as variables or control properties, is lost. In other words, HTTP doesn’t maintain the state of the application. This is illustrated in figure 1-5.

Here, you can see that a browser on a client requests a page from a web server. After the server processes the request and returns the page to the browser, it drops the connection. Then, if the browser makes additional requests, the server has no way to associate the browser with its previous requests. Because of that, HTTP is known as a stateless protocol.

Although HTTP doesn’t maintain state, ASP.NET provides several ways to do that, as summarized in this figure. First, you can use view state to maintain the values of server control properties. For example, you can use view state to preserve the Text properties of label controls that are changed as a web form is processed or to maintain a list of items in a drop-down list. Because ASP.NET implements view state by default, you don’t need to write any special code to use it.

Second, you can use session state to maintain data between executions of an application. To make this work, ASP.NET creates a session state object that is kept on the server whenever a user starts a new session. This session object contains a unique session ID, and this ID is sent back and forth between the server and the browser each time the user requests a page. Then, when the server receives a new request from a user, it can retrieve the right session object for that user. In the code for your web forms, you can add data items to the session object so their previous values are available each time a web form is executed.

Third, you can use an application state object to save application state data, which applies to all of the users of an application. For example, you can use application state to maintain global counters or to maintain a list of the users who are currently logged on to an application.

Fourth, you can use the profile feature to keep track of user data. Although a profile is similar to a session state object, it persists between user sessions because it is stored in a database. When you use profiles, for example, you can keep track of the last three products that a user looked at in his last session. Then, when the user starts a new session, you can display those products in a “Recently viewed items” list.

Why state is difficult to track in web applications

Concepts

  1. State refers to the current status of the properties, variables, and other data maintained by an application for a single user. The application must maintain a separate state for each user currently accessing the application.
  2. HTTP is a stateless protocol. That means that it doesn’t keep track of state between round trips. Once a browser makes a request and receives a response, the application terminates and its state is lost.

Four ASP.NET features for maintaining state

  1. ASP.NET uses view state to maintain the value of form control properties that the application changes between executions of the application. Since view state is implemented by default, no special coding is required.
  2. When a user starts a new session, ASP.NET creates a session state object that contains a session ID. This ID is passed from the server to the browser and back to the server so the server can associate the browser with an existing session. To maintain session state, you can add program values to the session state object. 
     
  3. When an application begins, ASP.NET creates an application state object. To maintain application state, you can add program values to the application state object. These values are available to all users of the application until the application ends. 
     
  4. ASP.NET can also maintain a profile for each user of an application. Because profiles are stored in a database, the profile data is maintained from one user session to another. This makes it easier to personalize an application.

Figure 1-5  How state is handled in ASP.NET applications

An introduction to ASP.NET application development

In the three topics that follow, you’ll find out what software you need for developing ASP.NET web applications, what the components of the .NET Framework are, and what development environments you can work in.

The software you need

The first table in figure 1-6 summarizes both the client and the server software that you need for developing ASP.NET applications. On your own PC, you need an operating system like Windows XP or Windows Vista, the Microsoft .NET Framework 3.5, and a browser like Microsoft Internet Explorer. You also need Visual Studio 2008 if you want to get the benefits from using that Integrated Development Environment (IDE).

If you’re using a server for your development, it will need a server operating system like Windows Server 2003 or later, Microsoft .NET Framework 3.5, and Internet Information Services. If you’re going to develop applications from a remote computer, it will also need FrontPage Server Extensions. And if you’re going to develop applications for the Internet, it will need an FTP server. In appendix A, you can get information about installing the software for both client and server.

Because most ASP.NET applications require database access, you also need a database server such as Microsoft SQL Server. For development work on your own PC, you can use SQL Server 2005 Express Edition, which is a scaled-back version of SQL Server that comes with Visual Studio 2008. But you’ll probably need SQL Server itself on the server for a production application.

If you’re developing production applications, you should also download and install other web browsers on your PC including Mozilla Firefox and Opera. That way, you can test your applications with a variety of popular browsers.

The second table in this figure shows that Visual Studio 2008 is available in several editions. Most professional developers will work with either the Standard Edition or the Professional Edition. But large development teams may use the Team System edition, which includes features designed for specialized development roles such as architects, developers, and testers.

A free alternative is Visual Web Developer 2008 Express Edition. This product is designed for individual developers, students, and hobbyists, and most of the features in this book will work with this edition.

The third table in this figure lists some of the most important new features of ASP.NET 3.5. Because each of these features is presented in detail later in this book, I won’t describe them here. But this table should show you that ASP.NET 3.5 provides some new features that you may want to use in your new applications.

Software requirements for ASP.NET 3.5 application development  

 

 

Client

Server

Windows XP or later

Windows Server 2003 or later

Microsoft .NET Framework 3.5

Microsoft .NET Framework 3.5

A browser like Internet Explorer (6.0 or later) Visual Studio 2008

Internet Information Services 6.0 or later Microsoft SQL Server or equivalent database FrontPage Server Extensions (for remote development only)

 

 

Visual Studio 2008 Editions

 

 

Description
Visual Studio 2008 Standard Edition Supports Windows and Web development using Visual Basic, C#, and C++.
Visual Studio 2008 Professional Edition Same as Standard Edition with several additional features such as additional deployment options and integration with SQL Server 2005.
Visual Studio 2008 Team System The top-of-the-line version of Visual Studio, with special features added to support large development teams.
Visual Web Developer 2008 Express Edition Free downloadable edition for web development in Visual Basic, C#, or J#.

 

 

New programming features for ASP.NET 3.5

 

 

 FeatureChapter Description
Nested master pages 9 Lets you define the overall look of a web site with one master page and then define the look of individual portions of the web site with other master pages that refer to the main master page.
ListView control 16 Lets you display, sort, insert, update, and delete the data in a bound data source. Provides a highly-customizable interface.
DataPager control 16 Adds paging capabilities to the ListView control. The DataPager control is displayed separately from the control it’s used to page.
LINQ data source control 18 Provides for using LINQ (Language-Integrated Query) to query and update a variety of data sources.
AJAX 25 Provides for developing web pages that are more responsive to the user and reduce the load on the web server.

 

 

Figure 1-6   The software you need for developing ASP.NET 3.5 applications

The components of the .NET Framework

Because you should have a basic understanding of what the .NET Framework does as you develop applications, figure 1-7 summarizes its major components. As you can see, this framework is divided into two main components, the .NET Framework Class Library and the Common Language Runtime, and these components provide a common set of services for applications written in .NET languages like Visual Basic or C#.

The .NET Framework Class Library consists of classes that provide many of the functions that you need for developing .NET applications. For instance, the ASP.NET classes are used for developing ASP.NET web applications, and the Windows Forms classes are used for developing standard Windows applications. The other .NET classes let you work with databases, manage security, access files, and perform many other functions.

Although it’s not apparent in this figure, the classes in the .NET Framework Class Library are organized in a hierarchical structure. Within this structure, related classes are organized into groups called namespaces. Each namespace contains the classes used to support a particular function. For example, the System.Web namespace contains the classes used to create ASP.NET web applications, and the System.Data namespace contains the classes used to access data.

The Common Language Runtime, or CLR, provides the services that are needed for executing any application that’s developed with one of the .NET languages. This is possible because all of the .NET languages compile to a common Intermediate Language (or IL). The CLR also provides the Common Type System that defines the data types that are used by all the .NET languages. That way, you can use the same data types regardless of what .NET language you’re using to develop your application.

To run an ASP.NET application, the web server must have the .NET Framework installed. However, the client computers that access the web server don’t need the .NET Framework. Instead, the client computers can run any client operating system with a modern web browser.

The .NET Framework

Description

  1. .NET applications work by using services of the .NET Framework. The .NET Framework, in turn, accesses the operating system and computer hardware.
  2. The .NET Framework consists of two main components: the .NET Framework Class Library and the Common Language Runtime. 
     
  3. The .NET Framework Class Library provides pre-written code in the form of classes that are available to all of the .NET programming languages. These classes are organized into groups called namespaces. The classes that support ASP.NET web programs are stored in the System.Web namespace. 
     
  4. The Common Language Runtime, or CLR, manages the execution of .NET programs by coordinating essential functions such as memory management, code execution, security, and other services. 
     
  5. The Common Type System is a component of the CLR that ensures that all .NET applications use the same data types regardless of what programming languages are used to develop the applications. 
     
  6. All .NET programs are compiled into Microsoft Intermediate Language (MSIL) or just Intermediate Language (IL), which is stored on disk in an assembly. This assembly is then run by the CLR.

Figure 1-7  The components of the .NET Framework

Three environments for developing ASP.NET applications

Figure 1-8 shows three common ways to set up a development environment for coding and testing ASP.NET applications. As you’ll see, each setup has its advantages and disadvantages. The environment you choose will depend on your development needs and on the resources that are available to you.

The simplest development environment is a standalone environment. In this case, a single computer serves as both the client and the server. Because of that, it must run an operating system that supports ASP.NET development, and it must have the .NET Framework and Visual Studio 2008 installed. Because Visual Studio 2008 comes with its own development server for local testing, you don’t have to install IIS when you use a standalone environment. Also, since Visual Studio comes with SQL Server 2005 Express Edition (or just SQL Server Express), you don’t have to install a separate database product.

The second development environment works with separate client and server computers that are connected via a local area network. Here, the client computer has Windows, the .NET Framework, and Visual Studio 2008 installed, while the server runs Windows Server with the .NET Framework, IIS, and FrontPage Server Extensions (FPSE). FPSE provides the services that Visual Studio 2008 uses to communicate with a web site on a remote computer. In addition, the server uses SQL Server to handle database access. With this environment, more than one programmer can work on the same application, but all of the programmers are located at the same site.

With the third development environment, the client computers are connected to the server via the Internet rather than a LAN. This makes it possible to work with a web site that’s hosted on another server. This environment requires an FTP server, which is used to copy the files in a web site between the client computer and the server. The FTP server uses File Transfer Protocol (FTP) to perform the copy operations, and IIS can be configured to act as an FTP server as well as a web server. So if a web site is hosted on a server that you have access to, you can configure the server so remote users can access it using FTP.

Standalone development

Local area network development

Internet development

Description

  1. When you use standalone development, a single computer serves as both the client and the server. Because Visual Studio comes with a scaled-back web server called the ASP.NET Development Server (or just development server), you don’t need to use IIS for testing web applications on your own PC. However, you do need to use IIS to test certain features of web applications.
  2. When you use a local area network (LAN), a client computer communicates with a server computer over the LAN. With this setup, two or more programmers at the same site can work on the same application. This setup requires that FrontPage Server Extensions (FPSE) be installed on the server. 
     
  3. When you use Internet development, a client computer communicates with a server computer over the Internet. With this setup, programmers at different locations can work on the same application. This setup requires an FTP server on the server. The FTP server uses File Transfer Protocol (FTP) to transfer files between the client computer and the server.

Figure 1-8  Three environments for developing ASP.NET applications

Please check back tomorrow for the conclusion to this series.

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials