The arrivar of.net has changed the face of web development with Microsoft technologies .With the Visual Studio.NET IDE you can now move seamlessly from building C# desktop applications to building web applications,with all the facililties Provided by the VS.NET environment.
With this book you’ll learn the fundamentals of the web environment and hou VS.NET make it accessible to C# Programmmers.you’ll build a working web site that demonstrates all the elements of a C# web application.we’ll take a step-by-step approach to each example,as we explore the essential technologies and how VS.NET helps us to integrate them into a highly interactive ,attractive web application.
What you will learn in this book
How to create dynamic web pages with ASP.NET web rorms and web server controls
How to display and maipulate data using ADO.NET.and Visual Studio.NETcomponents
How to create XML file and XML schemas,and how to use them for data transfer
How to mintegrate your web applications with others,through web serices in ASP.NET and IIS.
How to eliminate bugs and unexpected failures,through effective debugging and exception-handling techniques
How to improve the performance of your application and prepare it for release
The introduction of .NET has blurred the lines between previously distinct programming disciplines,and it has done so to great effect for developers. With so much functionality encapsulated by the .NET Framework class library, some diverse tasks have gained a common programming interface.
One area in which this change is particularly striking is that of web development. Before .NET, web application programming "the Microsoft way" was all about ASP. At the time, ASP was new, accessible, and exciting - but it was also script-based and inefficient, and the IDEs were disjointed. Microsoft has channeled the lessons it learned from ASP into its .NET Framework. Now, with ASP.NET (the .NET web development technology), we can create efficient, interactive Internet applications using the same languages that we would use for Windows desktop applications.
In Visual Studio .NET, Microsoft has taken this idea a stage further; not only does the code look similar, but the GUI looks similar too. Visual C4~ .NET's familiar form-based interface is used for development of web applications as well as for desktop programs. If you want to, you can create a web application without ever seeing a line of HTML code, and you can take advantage of all the facilities for testing and debugging that Visual Studio .NET provides to programmers of all disciplines.
The structure of class libraries in the .NET Framework is such that the methodology we use is the same- regardless of whether we're developing desktop applications or web applications. ASP.NET is really just a series of classes in the .NET Framework, in exactly the same way as the Windows Forms classes. From this perspective, the move from desktop application development to web development shouldn't be too much of a leap.
Yet there are some major differences that we need to consider when move to web development. We are no longer talking about applictions installed and running on individual machines; instead; we're talking about hosting an application on a central server, ready to be accessed by hundreds or thousands of remote clients every hour. The problem domain is now quite different, and more concerned with performance and scalability issues to ensure that the end user's experience is as smooth as possiblel
In this book, we'll set out to understand the issues involved in the web development paradigm, and how they're different from those we're used to in desktop application development. With these principles clear in our minds, we can then consider how to set about building our applications; and beginning at Chapter 3, we'll build a feature-rich, interactive web application called Friends Reunion using CS, ASP.NET, and Visual Studio .NET.
The emphasis is on learning by practice. Every single example in the book is described step by step, and we'll outline and explain every single stage in the development, debugging, and deployment of the Friends Reunion application. The source code for the application is available online at http://www.wrox.com.
Who Is This Book For?
This book is predominantly targeted at developers who have some experience in the Cf language (perhaps through practical application of the language, or simply from a C4~ tutorial book). These developers may fall into one of two groups:
Readers who have little or no web development experience, have gained their C~ experience mostly in the context of desktop applications, and are seeking to apply this Cf expertise in web development in .NET
Readers who have gained some web development experience using ASP, PHP, or other technologies, and are seeking to move into web development using .NET and their favored C# programming language.
This book does not assume that you have programmed for the web environment before; but it does assume that you have some familiarity with the CS programming language. Previous experience of the Visual Studio .NET integrated development environment (IDE) is not essential, but would be helpful. Similarly, we assume no previous experience of HTML, XML, databases, or any of the other technologies mentioned in this book - though a little background knowledge does no harm.
What Does This Book Cover?
The first two chapters of this book are introductory. They'll set out the preliminary material that enables us to begin work on the Friends Reunion web application in Chapter 3. Each of the remaining chapters (from 3 to 13) examines a different aspect of web application development using C# and ASP.NET. In each chapter, we study an aspect both in general terms and within the context of the Friends Reunion application. Over the course of these eleven chapters, we will build, test, debug, and deploy a rich interactive web application - and you'll see every single step.
Here's a summary of the chapters in this book:
Chapter 1 is an introduction to the web environment. It discusses the similarities and differences between web applications and desktop applications, and exl:flains what happens behind the scenes when a user employs a browser to request a web page. The intention is to give a clear insight into the issues that influence the way we design applications for the Web, and to set the scene for the remainder of the book. We also set up the web server here, and create a couple of simple examples to get things started.
In Chapter 2, we move on to create some basic ASP.NET web forms using Visual Studio .NET. We look at how web forms are processed and the life cycle of a page, and we demonstrate it all by walking through our first ASP.NET application.
Chapter 3 is all about the server control. The server control is the core part of any web form it's at the heart of the development of dynamic, interactive web sites in .NET. Visual Studio .NET allows us to drag and drop server controls onto our web forms in exactly the same way that we insert Windows Forms controls into a Windows desktop application; and we can add code to our forms to interact with these controls in much the same way, too.
In Chapters 4 and 5 we turn our attention to data. Most interactive web applications rely on the existence and manipulation of data of some form or other, and on storage of that data (either in a full-scale database or some other format). In Chapter 4 we use ADO.NET to access and manipulate data. In Chapter 5 we see how data binding techniques make it easy to display data on our pages in a user-friendly manner; we also see how to apply templates to our web forms to alter the look and feel of our data-bound controls.
Chapter 6 is about applications, sessions, and state. By nature, the web is a stateless medium when you request a web page, the web server delivers it and then forgets about you. If we want our web applications to recognize a user when they make multiple page requests (for example, as they browse an e-commerce application adding items to a shopping basket) then we need to know about the different techniques we can use to retain state across pages, or for a session, or across an application.
Chapters 7 and 8 focus on XML - a topic that has become very important as widespread Internet connectivity becomes the norm. In Chapter 7 we look at the concept of markup and how it is widely relevant to data-driven applications, and we create our own XML language by way of an XML schema. In Chapter 8, we explore how we can use that XML schema to facilitate a data transfer feature - exploiting XML's nature as the perfect vehicle for data transfer across the Internet.
In Chapter 9 we turn briefly away from web sites, to learn about a different type of web application - the web service. Web services enable us to expose our application's functionality to other "client" applications - these applications make requests using standards and protocols over the Internet. This also means that we can use other people's web services in our code as if theywere components on our own system - even though they are only accessible across the Internet.We'll examine both how to create our own web services and how to consume existing services.
Chapter 10 is about ASP. NET authentication, authorization, and security. The role of security in an application is motivated by the need to restrict a user's (or application's) access to certain resources, or their ability to perform certain actions. For example, we may want to include administrative tools in our web application, and to prevent access to these admin pages for all but authorized users. This chapter looks at the tools available to us in ASP.NET for authenticating and authorizing users of our applications.
Chapter 11 tackles two distinct but related subjects: debugging and exception handling. Debugging is much easier when we understand the different types of bugs that can occur, and easier still with the array of debugging tools and techniques made available by Visual Studio .NET and the .NET Framework - so we'll study all that in the first half of the chapter. In the second half, we use the .NET exception mechanism to handle some potential input errors that could occur at run time, and prevent the application from crashing in a heap.
In Chapter 12 we tackle two more different but related subjects: performance and caching.We set out to understand what we mean by "good performance", and we demonstrate a number of techniques we can use to analyze our application in realistic conditions. We put the application under stress to see what happens, and we identify and fix a number of different bottlenecks. We understand the issues related to caching, and employ a number of different caching techniques to save our application some processing effort and hence optimize use of our server's resources.
Finally, in Chapter 13, we see how to prepare our application for deployment. Visual Studio .NET provides us with some easy-to-use tools that enable us to build our own deployment wizards. We demonstrate how to prepare the application for deployment - web site, database, and all - by wrapping it all up into an easy-to-use installation wizard.
There are two appendices. Appendix A contains a brief overview of the structure and functionality of the Friends Reunion web application. Appendix B contains more information about the setup of the IIS 5.x web server and the MSDE data engine, and it also contains a preview of Microsoft's new web server software, IIS 6.0.
What You Need to Use This Book
The following is the list of recommended system requirements for running the code in this book:
A suitable operating system. Either Windows 2000 Professional, Server or Advanced Server Edition (at the time of writing, the latest service pack is SP2), or Windows XP Professional Edition.
Internet Information Server (IIS) 5.0 or 5.1. This is shipped with the operating systems listed above. IIS 6.0 is not released at the time of writing, but will be suitable alternative web server software.
The .NET Framework SDK.
Visual Studio .NET (or Visual C# .NET) Standard Edition or higher.
The SQL Server Desktop Engine (also known as MSDE), or Microsoft SQL Server.
MSDE is shipped with the .NET Framework SDK, and also with Visual Studio .NET and Visual C# .NET. To install it, execute the file InstMSDE. oxe (which is found in the IProgram FileslMicrosoft. NETIFrameworkSDK~SampleslSetup~MSDE folder). MSDE does not offer the same admin tools as SOL Server, but there are some useful command-line utilities detailed in the file IProgram Files~Microsoft. NE~FrameworkSDK~Samples~Setup htmllConfigDetails.htm. Moreover, note that Visual Studio .NETprovides a useful UI to any SQL Server or MSDE database.
Note that Windows XP Home Edition does not come with IlS, and cannot run//IS. For ASP.NET web development on Windows XP Home Edition, you may consider the ASP.NET Web Matrix tool, available for free download from http://www.asp.net. This tool offers limited ASP.NET web server functionality, but you won't be able to run web projects in Visual Studio .NET on this version.
This book assumes that you have at least some familiarity with desktop application programming in a Visual C#.NET environment. We'll cover other technologies (such as ASP.NET, ADO.NET, XML, and SQL) in sufficient detail as we progress through the book - although a little prior knowledge never goes amiss.
Style Conventions
We have used certain layout and font styles in this book that are designed to help you to differentiate between the different kinds of information. Here are examples of the styles that are used, with an explanation of what they mean.
As you'd expect, we present code in two different ways: in-line code and displayed code. When we neec to mention keywords and other coding specifics within the text (for example, in discussion relating to an if...else construct or the System. Web namespace) we use the single-width font as shown in this sentence. If we want to show a more substantial block of code, then we display it like this:
Sometimes, you will see code in a mixture of gray and white backgrounds, like this:
private void Page_Load(object sender, System. EventArgs e)
{
HeadericonImageUrl=Request.ApplicationPath + "/Images/winbook.glfii;
= "Inf0rmatiVe Page";
}
In cases like this, we use the gray shading to draw attention to a particular section of the code – perhaps because it is new code, or it is particularly important to this part of the discussion.
Advice, hints, and background inJbrmation come in this type of font.
Important pieces Of information Come in boxes like this. Bullets appear indented, with each new bullet marked as follows:
Important Words are in a bold type font.
Words that appear on the screen, or in menus like File or Window, are in a similar font to the one you would see on a Windows desktop.
Keys that you press on the keyboard like Ctrl and Enter, are in italics. Customer Support and Feedback
We value feedback from our readers, and we want to know what you think about this book: what you liked, what you didn't like, and what you think we can do better next time. You can send us your comments, either by returning the reply card in the back of the book, or by e-mail to feedback@wrox.com. Please be sure to mention the book's ISBN and title in your message. How to Download the Source Code for the Book
When you visit the Wrox site, http://www.wrox.com/, simply locate the title through our Search facility or by using one of the title lists. Click on Download in the Code column, or on Download Code on the book's detail page. When you click to download the code for this book, you are presented with a page that has three options:
If you are already a member of the Wrox Developer Community (if you have already registered on ASPToday, C#Today, or Wroxbase), you can log in with your usual username and password combination to download the code.
If you are not already a member, you have the option of registering for free code downloads. By registering, you will be able to download several free articles from Wrox Press. It will also enable us to keep you informed about updates and new editions of this book.
The third option is to bypass registration completely and simply download the code.
Registration for code download is not mandatory for this book. If you do register for the code download, your details will not be passed to any third party. For more details, you can review our terms and conditions, which are linked from the download page.
When you reach the code download section, you will find that the files that are available for download from our site have been archived using WinZip. When you have saved the files to a folder on your hard drive, you,will need to extract the files using a de-compression program such as WinZip or PKUnzip. When you extract the files, the code is extracted into chapter folders. When you start the extraction process, ensure your software (WinZip, PKUnzip, etc.) is set to use folder names.
Errata
We've made every effort to make sure that there are no errors in the text or in the code. However, no one is perfect and mistakes do occur. If you find an error in one of our books, like a spelling mistake or a faulty piece of code, we would be very grateful for feedback. By sending in errata you may save another reader hours of frustration, and of course, you will be helping us provide even higher quality information. Simply e-mail the information to support@ wrox.com, where your information will be checked and, if correct, posted to the errata page for that tide, or used in subsequent editions of the book.
To find errata on the web site, go to http://www.wrox.com/, and simply locate the title through our Advanced Search or title list. Click on the Errata link, which is below the cover graphic on the book's detail page.
Technical Support
If you would like to make a direct query about a problem in the book, you need to e-mail support@wrox.com. A typical e-mail should include the following things:
In the Subject field, tell us the book name, the last four digits of the ISBN (7329 for this book), and the page number of the problem.
In the body of the message, tell use your name, contact information, and the problem. We won't send you junk mail. We need these details to save your time and ours. When you send an e-mail message, it will go through the following chain of support:
1. Customer Support - Your message is delivered to one of our customer support staff- they5 the first people to read it. They have files on most frequently asked questions and will answ anything general about the book or the web site immediately.
2. The Editorial Team - Deeper queries are forwarded to the technical editor responsible for tbook. They have experience with the programming language or particular product, and are able to answer detailed technical questions on the subject. Once an issue has been resolved, the editor can post the errata to the web site.
3. The Authors - Finally, in the unlikely event that the editor cannot answer your problem, th will forward the request to the author. We do try to protect the author from any distractions their writing; however, we are quite happy to forward specific requests to them. All Wrox authors help with the support on their books. They will mail the customer and the editor wi their response, and again all readers should benefit.
Note that the Wrox support process can only offer support to issues that are directly pertinent to the content of our published title. Support for questions that fall outside the scope of normal book support is provided via the community lists of our
http://p2p.wrox.com/forum.
p2p.wrox.comFor author and peer discussion join, the P2P mailing lists. Our unique system provides programmer to
programmerTM contact on mailing lists, forums, and newsgroups, all in addition to our one-to-one e-mail support system. Wrox authors and editors and other industry experts are present on our mailing lists.
At p2p.wrox.com you will find a number of different lists that will help you, not only while you read this book, but also as you develop your own applications. Particularly appropriate to this book are the aspx and aspx_professional lists in the .NET category of the web site.
To subscribe to a mailing list just follow these steps:
1. Go to http://p2p.wrox.com/
2. Choose the appropriate category from the left menu bar
3. Click on the mailing list you wish to join
4. Follow the instructions to subscribe and fill in your e-mail address and password
5. Reply to the confirmation e-mail you receive
6. Use the subscription manager to join more lists and set your e-mail preferences