This action might not be possible to undo. Are you sure you want to continue?
Part of the .NET Framework, ASP.NET allows developers to build dynamic web applications and web services using compiled languages like VB.NET and C#. Using Visual Studio, the development tool from Microsoft, web developers can develop very compelling applications using ASP.NET, with the ease of drag-and-drop server controls. Currently in its next major release, ASP.NET 2.0 is slated to be released in November 2005. In This Article: 1. 2. 3. 4. 5. 6. 7. A Brief History of ASP.NET How ASP.NET Works What Do You Need to Run ASP.NET? Visual Studio and ASP.NET ASP.NET Improvements New Features in ASP.NET 2.0 Summary
In the early days of the Web, the contents of web pages were largely static. Pages needed to be constantly, and manually, modified. To create websites that were dynamic and would update automatically, a number of server-side technologies sprouted up, including Microsoft's Active Server Pages (ASP). ASP executed on the server side, with its output sent to the user's web browser, thus allowing the server to generate dynamic web pages based on the actions of the user. These server-side technologies are important contributions to the development of the Web. Without them, web applications that we've become accustomed to today, such as Amazon.com, eBay.com, and so on, would not be possible. In this article, I will delve into ASP.NET, with a look at what it is, how it works, and the newest important features of 2.0.
A Brief History of ASP.NET
Microsoft Active Server Pages (ASP) started its life as a public beta (v1.0) in October 1996 as an upgrade to Internet Information Server (IIS) 2.0. From that point on, ASP slowly evolved into version 2.x, and then finally 3.0. In the initial three versions, ASP used a scripting language, VBScript, as the default language. Using a scripting language has its flaws; code is interpreted rather than compiled, and using VBScript as the default language turned some people off (though technically you can configure ASP to use other languages such as JScript and Perl, but this was not commonly done). This interpreted code model of ASP seriously limited performance. In early 2000, Microsoft introduced the new .NET Framework, and together with it, introduced the upgrade of ASP: ASP.NET 1.0 (previously known as ASP+). Over the last few years, ASP.NET has gone through a few evolutions, from ASP.NET 1.0 to 1.1, and now to ASP.NET 2.0, due to be released at the end of this year (November 2005).
0: A by the same user are treated just like any request.NET Related Reading How ASP. you typically need to write pages of code in order to preserve the state of the page after the user has posted a value back to the server. 7. IIS will pass the request to the ASP.NET. 6. 3.NET Works When a web browser requests a page from a web server. such as cookies and the use of query strings for passing information to and from the server and the client. You can now use the following . This stateless nature makes writing web applications a challenge.NET runtime.NET languages: y y y C# J# VB. the web server (IIS) will first check if the request is for an HTML page. 7. and then unloaded. In ASP. you are not limited to scripting languages. If it is.In ASP.NET Pages: 1. the request is fulfilled by fetching the files from the OS and then returning it to the client (web browser). 4. Put simply. One of the inherent problems with the HTTP protocol is its stateless nature. Subsequent requests ASP. 4.aspx extension.asp.NET is able to run side by side with classic ASP on the same server. You will learn more on this in the following sections.NET page. the server Developer's Notebook makes no attempt to remember what the user has previously By Wei-Meng Lee requested. In classic ASP. all of these mundane tasks (collectively known as state management) are accomplished by the ASP. 5. which will then process the application and return the output to the client. 5. If the client is requesting an ASP. Several mechanisms have been devised over the years.NET. This is to ensure that ASP. 2. 8 . which uses the extension . because the application developer must explicitly devise mechanisms to enable the server to remember the previous state of the application. fulfilled.NET runtime.NET pages use the . 3. Pages: 1. 8 Print Subscribe to Windows Subscribe to Newsletters ShareThis What Is ASP.NET 2. ASP. a request made by a user is loaded into memory. 6. 2.
To understand what I mean by state management.Text = "Hello " & TextBox1.Web.State Management As mentioned previously. When the button is clicked.Page Protected Sub Button1_Click( _ ByVal sender As Object. it displays the name of the user in the Label control: Partial Class _Default Inherits System. consider the following example.UI. Figure 3. . A simple ASP. _ ByVal e As System.NET automatically takes care of state management.EventArgs) _ Handles Button1. The following code is the code behind for the application.NET application The example in Figure 3 prompts the user to enter a name and then click the Click Me button.Text End Sub End Class Here is how it looks like when run (see Figure 4).Click Label1. ASP. shown in Figure 3.
you would need to explicitly write code in your application to ensure that the text in the TextBox control remained visible. To understand how ASP.org/1999/xhtml"> <head><title> Untitled Page </title></head> <body> <form method="post" action="Default.1//EN" "http://www. If you were using classic ASP.org/TR/xhtml11/DTD/xhtml11. examine the source of the page in Internet Explorer (do a View -> Source): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. Testing the application Notice that after the button is clicked.w3. the text contained within the TextBox control is still available.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU5MTA2ODYwOQ9kFgICAw9kFgICBQ8PFgIeBFRleHQFE0hlbGxvICBX ZWktTWVuZyBMZWVkZGQVx6NLNcu0P+TBFnYu2ubB4x3vdQ==" /> </div> <div> Please enter your name:<br /> <input name="TextBox1" type="text" value="Wei-Meng Lee" id="TextBox1" /> <input type="submit" name="Button1" value="Click Me" id="Button1" /> <br /> <span id="Label1">Hello Wei-Meng Lee</span><br /> <br /> </div> </form> .NET maintains state between postbacks (when you submit a request back to the server).dtd"> <html xmlns="http://www.w3.Figure 4.
2. 3. 8 Tracing and Debugging In the previous example.aspx. 7. I mentioned that you can view the Web Form in either Design view or Code-Behind view. not encrypted.vb" Inherits="_Default" %> . Pages: 1.NET is the enhanced support for tracing and debugging. (It does so by examining the content of the _VIEWSTATE element.</body> </html> In particular. look out for the hidden input element known as _VIEWSTATE. Visual Studio supports yet another view: Source view. 6. This element contains the state information of the page and is passed between the client and the server. you can view the source of a page (the markup elements that make up the UI of a page). By storing information in this element. 4. Switching to Source view One useful feature in ASP. Using Source view. 5. You can trace the flow of your application by using the Trace attribute in the <Page> directive: <%@ Page Language="VB" Trace="true" AutoEventWireup="false" CodeFile="Default.) Note that the information in the _VIEWSTATE element is only encoded. Figure 5 shows the Source view of the previous example: Figure 5. the server is able to maintain the state of the page as it gets posted back to the server.
4. 3. For example. 8 You can also insert Trace statements into your application.EventArgs) _ Handles Button1. 7. 6.When you enable tracing.Text = "" Then Trace. You would be able to examine detailed execution information such as the sequence in which the events are fired. 2. Figure 6. as well as the values of the environment variables. 5. 7. and another to simply display the contents of the TextBox control: Protected Sub Button1_Click( _ ByVal sender As Object.NET application Pages: 1. 8 Next Page What Is ASP. you will see output similar to that shown in Figure 6. 6.NET Pages: 1.Click If TextBox1. 4. Enabling tracing for your ASP. and so on. 3. 5. _ ByVal e As System. in the following code I have inserted two Trace statements: one to display a warning when the user did not enter a string for the TextBox control. 2.Warn("Empty string for textbox1") .
Text End Sub When run. notice the red warning text (see Figure 7) when the button is clicked. Figure 7. the trace message will be printed in black (see Figure 8). .Text = "Hello " & TextBox1.Write(TextBox1.Else Trace.Text) End If Label1. Displaying a warning message in red But if you type some text into the TextBox control.
NET web application in real time." there is no need for you to remove the trace statements.Figure 8. Besides tracing. . you can simply turn off tracing by setting the Trace attribute to "off. you also have the ability to step through the execution of your application code. Displaying trace information The nice feature about the Trace class is that when it comes to time to deploy the application. Figure 9 shows that you can perform debugging on an ASP.
To illustrate how caching works in ASP. 5. Time-based caching: Another technique for caching is based on time. let's consider an example using output caching. Assuming that you have an ASP. Smart caching with dependencies: The cache would automatically invalidate itself when some external events happen (such as the modification of a text file. 4. SQL cache dependency: SQL cache dependency is the ability to invalidate a database cache if the data in a table is changed. 2.Figure 9. 6. the cache can expire on a certain date. add a new OutputCache directive to the ASP. Caching objects in a page: While output caching is useful.NET. Debugging an ASP. 3. ASP. 7. 8 Caching Caching of web pages is an effective way of increasing performance while minimizing the use of precious server resources. There are two ways in which you can use time-based caching--sliding and absolute expiration. and so on).NET web form.NET supports various forms of caching: y y y y y Output caching: Output caching caches the output of a page (or portions of it) so that a page's content need not be generated every time it is loaded. or it will only be available for a certain period of time. rather than entire pages. a much more powerful and flexible approach would be to cache individual objects in your web application.NET form: . For example.NET application using Visual Studio Pages: 1.
based on the query string supplied to the page. it is refreshed.<%@ OutputCache Duration="15" VaryByParam="*" %> <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx. This means that if the page is loaded again within the next 15 seconds.aspx?name=John&newsid=45 The following URLs will cause the second request to be refreshed: http://localhost/Caching/WebForm1.aspx?name=John&newsid=12 The query string passed to the page is name=John&newsid=12. if part of the content of the page is retrieved from a database). For example. which means all keys will cause the page to be regenerated: <%@ OutputCache Duration="15" VaryByParam="*" %> If you want to cache the page regardless of query string. In this example.aspx?name=John&newsid=12 http://localhost/Caching/WebForm1. suppose I change the VaryByParam attribute to: <%@ OutputCache Duration="15" VaryByParam="Name" %> The page will then be cached according to the Name key.aspx?name=John&newsid=12 http://localhost/Caching/WebForm1. as the cache will only be refreshed if the value of Name changes: http://localhost/Caching/WebForm1. you can use the value none: . the Web server will serve the same content without needing to dynamically regenerate the page (and thus avoiding access the database. the output of the page will be cached for 15 seconds. Now.NewsID" %> In this case. if I used the following URL: http://localhost/Caching/WebForm1. this is equivalent to using a *.vb" Inherits="Caching. you simply add the NewsID key into the VaryByParam attribute: <%@ OutputCache Duration="15" VaryByParam="Name. This means that if I issue requests using the following two URLs.WebForm1"%> The OutputCache directive specifies the various criteria for caching the page.aspx?name=Michael&newsid=12 If you want to force the page to be regenerated if more than one key changes (such as Name and NewsID). The VaryByParam attribute specifies how the caching should be performed. the second request will still be from the cache.
As an additional protection. The following code segment shows part of web. 5.NET Caching" "SQL Cache Dependency" Pages: 1. 5.. it is always better to use integrated Windows security to access your database. 6. it's not such a good idea to save your connection strings as plain text in web. 8 Configuration Files ASP. rather than using SQL Server authentication and thus including your SQL server credentials in the connection string. 3. 4.config file stores information such as: y y y y y Security Database connection string Caching Debugging Globalization settings One of the best practices in ASP.Data.NET Pages: 1.SqlClient" /> </connectionStrings> <system. 2.. containing a database connection string: <configuration xmlns="http://schemas. without needing to modify your code. 6. 8 What Is ASP.<%@ OutputCache Duration="15" VaryByParam="none" %> Refer to my articles on ONDotnet. the web. However.Integrated Security=True" providerName="System.config.web> . 7. Initial Catalog=pubs.0"> <connectionStrings> <add name="pubsConnectionString" connectionString="Data Source="(local)". 3.NET uses external configuration files to store detailed information about the application. 2. 7.config file instead of hard-coding it into your code. For example. This allows you to change database servers easily.NET is to save your database connection strings in the web.microsoft.config.com for more information on caching: y y "ASP.com/ . you should ideally encrypt the connection strings so that it leaves no chance for a potential . 4.NetConfiguration/v2.
NET 2. Label. login.config. Controls ASP. there are now new controls that help you to perform data access. .config): y y DataProtectionConfigurationProvider RSAProtectedConfigurationProvider To learn how to encrypt your database connection string in ASP. and personalization using Web Parts.0. Earlier you had a glimpse of some of the controls (TextBox.NET 2. In ASP.html. New Features in ASP. improvements to the Page framework.0 to allow you to encrypt your connection strings (as well as other sections in web.0 can be grouped into three broad categories: new controls and control functionality.NET 2. In ASP.NET 2.NET 1. and Button) shipped in ASP.x. The new features in ASP.0. Two Protection Configuration Providers are available in .0 ships with several new controls to make the life of a web application developer easier. check out www. all without much plumbing on your part.ondotnet.NET 2.0 represents a huge leap over ASP.NET. Microsoft has taken this further by allowing you to encrypt the connection strings in web.NET 2.0.NET 2. Figure 10 shows the controls shipped with ASP.0.hacker to easily get more information about your database server. and new services and APIs (see Table 1). They are categorized based on their functionalities. site navigation.com/pub/a/dotnet/2005/02/15/encryptingconnstring.0 ASP.NET 2.NET 2.
NET 2. Besides using the new controls. behind the new Login controls you'll find the new collection of Membership APIs.0 lie the foundation services and APIs that do the heavy lifting needed to enable the controls to do their work.Figure 10. which reduces the amount of work you need to do to internationalize your web applications.NET is the improved support for localization. 3. registration of new users.NET 2.0 also supports "theming" through themes and skins. 8 Services and APIs Behind the various new controls in ASP. such as visual inheritance. Another noteworthy feature in ASP. you can directly make use of these APIs in code.0 Controls Data Controls Includes controls that simplify the connection to Page Framework Master Pages Visual page inheritance for Web Forms. Pages: 1. For example.0 supports some useful additions to its Page framework. 2. Besides Master Pages. New Features in ASP. such as user .NET 2. 7. allowing you to maintain a consistent look and feel for your websites.NET 2. and so on. 5. 6. technically known as Master Pages. which perform such tasks such as user authentication. Table 1. 4.0 Page Framework ASP.NET 2. The various controls in ASP. Services and APIs Membership The core service for user management. ASP.
NET 2. creation.NET 2. FileUpload. Have fun! To try out ASP. such as add user to role.com. a technology company specializing in hands-on training on the latest Microsoft technologies. Wei-Meng Lee (Microsoft MVP) http://weimenglee. download Visual Studio 2005 Beta 2. . retrieval of passwords. Also supports automatic generation of web services proxy class using WSDL. Profile Supports the personalization of websites through the Profile object.NET 2.0.data sources as well as the new GridView and DetailsView controls.0 for a spin today. globalize and localize your web applications. etc. refer to ASP. download Microsoft Visual Web Developer 2005 Express Edition Beta 2. authentication.NET. Of course.0: A Developer's Notebook. If you have never developed a web application before. Summary In this article. as well as the display of site maps. MultiView.developerlearningsolutions.blogspot. Themes and Skins Maintain consistent look and feel for the entire site by using Skins definitions grouped by themes. one of the easiest ways is to grab a copy of my book and spend a few good afternoon trying out all the features. I strongly encourage you to take ASP. Navigation Controls Contains controls that display site information and menus. if you are a MSDN subscriber. you have seen some of the most important features of ASP. Additional Standard Controls Contains controls such as ImageMap. or. inquire if user's in role. delete user from role.NET 2.com is a technologist and founder of Developer Learning Solutions http://www. Compilation Supports dynamic compilation of business logic without the need for explicit recompilation when the code is changed. Role Management Manages the assigning of roles to users. and TreeView. Login Controls Contains controls that makes website user management and user authentication easy and efficient.0. etc. Web Parts Localization Provides the infrastructure Simplify the steps needed to for creating Web Parts. You will be amazed at how easy it is to start building compelling applications with so little effort. deletion. Site Maps Supports the retrieval of site information. For a detailed discussion of the new features in ASP.
Return to ONDotnet. .com.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.