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. FilesThe 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
Maintaining State Between ASP and ASP.NETOne 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 DifferencesAnother 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.
NOTE You can see these and every other example in this book by going to: http://www.aspauthors.com/aspnetbyexample/ch03/ 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 |