Basic Differences Between ASP and ASP.NET

I l @ ve RuBoard

Before we build our first ASP.NET page, let's go over some of the basic differences between ASP and ASP.NET, with regard to the file system and organization, and some architectural considerations.


The first thing to note is that the file extension for an ASP.NET page is different from that of a Classic ASP page. Instead of using .asp, you use .aspx as your file extension. Similarly, in an ASP application you used the global.asa file to manage some of the application events, and in an ASP.NET application you will use the global.asax file. In addition to the global.asax file, an ASP.NET application also has a web.config file, which is used to set many application-specific configuration settings. Unlike the global.asax, web.config files are inherited by applications in subfolders . In fact, all .NET applications on a given server inherit from a base config file, machine.config, located in the operating system directory.

Table 3.1. Important ASP.NET File Types
Ex tension Replaces ASP File File Description
.asax .asa The global.asax file replaces the global.asa file and holds event handlers for the application, session, and page request events. The global.asax file is covered in Chapter 10, "ASP.NET Applications."
.ascx None ASP.NET User Controls must have the .ascx extension. User Controls are covered in Chapter 9, Using ASP.NET User Controls.
.asmx None ASP.NET Web Services use the .asmx extension. Chapter 11, "ASP.NET and Web Services," covers these files in detail.
.aspx .asp The default extension for ASP.NET pages, which take the place of ASP pages.
.config None Configuration files store application settings in XML format. The web.config file is the most commonly used configuration file. These files are described in Chapter 10, "ASP.NET Applications."
.cs None C# source files typically have the .cs extension.
.js None Jscript source files typically have the .js extension.
.vb None Visual Basic source files typically have the .vb extension.

Maintaining State Between ASP and ASP.NET

One thing to be aware of as you migrate your files from ASP to ASP.NET is that session state is not shared across the two architectures. That is, while you certainly can migrate to ASP.NET one page at a time, .aspx page and .asp pages cannot share the same session state. If your application relies heavily on session variables , this is something to consider. There are several ways to deal with this problem.

To maintain state between .asp and .aspx files, it is necessary to use an alternative to the built-in session object of either architecture. There are several possibilities, each with advantages and disadvantages, and because sessions have many known scalability issues in Classic ASP, it is likely that many sites will not make heavy use of them, and will not have a difficult time migrating to ASP.NET because of this. Instead of using session variables, you can use cookies, querystrings, or hidden form fields. Each of these techniques allows you to persist user information from page to page. For very small and non-sensitive data, it is sufficient to simply pass the actual data around. However, for more detailed or secure information, you should pass around a unique identifier that ties to a database that holds the actual data. Using any of these methods , you will be able to maintain application state between .asp and .aspx pages.

Language Differences

Another thing you will quickly run into as you convert your .asp pages to .aspx pages is the language difference. VBScript is no longer used; instead VB.NET (VB7) (or another .NET language) is used for ASP.NET development. JScript, although still supported, has undergone a great deal of revision in order to be compliant with .NET. This book will focus primarily on VB.NET and C# for its examples. Listings 3.1, 3.2 and 3.3 show a very simple page that uses code to display Hello World to the browser. You can see that there are some important language differences between the current ASP languages and the new ASP.NET languages.

Listing 3.1 Source code for HelloVB.asp.
 <%@ Language=VBScript %> <%Option Explicit%> <html> <head> </head> <body> <% Response.Write "Hello World" %> </body> </html> 
Listing 3.2 Source code for HelloVB.aspx.
 <%@ Page Language="VB" %> <html> <head> </head> <body> <% Response.Write("Hello World") %> </body> </html> 
Listing 3.3 Source code for HelloCS.aspx.
 <%@ Page Language="C#"%> <html> <head> </head> <body> <% Response.Write("Hello World"); %> </body> </html> 

Figure 3.1 is an example of what the output of one of these files would be. Displayed is HelloVB.aspx, but each of the files would produce the exact same output.

Figure 3.1. HelloVB.aspx.


You can see these and every other example in this book by going to:

As you can see, there are some subtle differences in syntax between VBScript and VB.NET. We will see as we move on through the book that C# has its own unique syntax as well, which is very close to C/C++, JScript, or Java. However, because all languages in ASP.NET rely on the same .NET Framework of objects, the code for any given function often looks very similar regardless of the language in which it was written.

For a quick reference to the VB.NET language, refer to Appendix C.A similar reference to C# is found in Appendix D.For now, just remember one key difference between VB and VBScript, which is that methods now require parentheses, and will not compile without them. We'll see more differences as we continue, and answer some questions you may have about the new C# language.

I l @ ve RuBoard

Asp. Net. By Example
ASP.NET by Example
ISBN: 0789725622
EAN: 2147483647
Year: 2001
Pages: 154

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: