Introduction: Planning an ASP.NET Web Site
Before you create a Web site, it is always helpful to plan the site before you begin creating pages and writing code. Planning the site in advance can make it easier to create the overall look of the site and of site navigation.
The size of a Web site can often determine the amount of planning you must do. A small, brochure-type Web site that just provides static information can be a relatively basic site that requires little planning. A Web site that accesses a data store, authenticates users, and that has localization and accessibility constraints can require more planning. Having a plan will save you time in the development and maintenance of the site.
The following topics cover information that pertains to the Web site as a whole, which includes information on the following:
The type of Web site that you select.
How you navigate through the site.
Ways to create a consistent look and layout for all the pages in the site.
How to access data from a data store.
There are two project types you can create in Visual Studio 2010. The default Web site project model uses a file directory structure to define the contents of a project. In this model, there is no project file, and all files in the directory are part of the project.
In contrast, in a Web application project, only files that are explicitly referenced in the solution's project file are part of the project. These files are displayed in Solution Explorer, and they are the only files that are compiled during a build.
The project file of a Web application project makes some scenarios easier to implement. For instance, you can subdivide one ASP.NET application into multiple Visual Studio projects by referencing files in different project files. You can also easily exclude files from the project.
Use Web application projects when you want to do the following:
Migrate large Visual Studio .NET 2003 applications to Visual Studio 2010.
Have control over the names of output assemblies.
Use standalone classes to reference page classes and user-control classes.
Build a Web application by using multiple Web projects.
Add pre-build and post-build steps during compilation.
ASP.NET data binding lets you bind components to data sources and to simple properties, collections, expressions, and methods. This provides greater flexibility when you use data from a database or other sources.
If the Web site accesses a data store, you should consider using the data source controls, because they are part of a common data pattern. This data pattern separates the data-access code and business logic code from the Web pages that form the presentation layer of the Web site. A data-access layer consists of methods that are used to access a data store. A business logic layer adds rules to the data access layer, such as restricting access on who can view or change the data. The presentation layer consists of pages that the user accesses to view and modify the data. For more information about creating these layers, see Walkthrough: Creating the Data Access and Business Logic Layers in ASP.NET.
You can implement this common data pattern by separating the presentation layer from the data and business logic layers by using the data source model in ASP.NET. By using such controls as the LinqDataSource, ObjectDataSource, and the SqlDataSource controls, you create a data access layer and business logic layer that are separate from the presentation layer.
You should also consider whether the Web site must use in-memory (cached) data. If a significant portion of the application data does not change frequently and is common across sessions or users, you can keep the data in memory on the Web server. This can reduce the number of requests to the database and speed up the user’s interactions. You create an in-memory database using the DataSet class. Another useful aspect of the DataSet object is that it enables an application to bring subsets of data from one or more data sources into the application space. The application can then handle the data in-memory, while retaining its relational shape.
As a site grows, and as you move pages around in the site, it can quickly become difficult to manage all the links. ASP.NET site navigation consists of server controls and classes that enable you to provide a consistent way for users to navigate the site. You can store links to all the pages in a central location (typically an XML file). You can render those links in lists or navigation menus on each page by including a SiteMapDataSource control to read site information. You then use a navigation server control such as the TreeView or Menu controls to display site information.
A key part of ASP.NET site navigation is the site map provider. This is a class that is used with a site map data source and exposes navigation information. For example, the default ASP.NET site map provider obtains site map data from an XML file that is named Web.sitemap, and communicates that data to the SiteMapPath Web server control directly.
Several features in ASP.NET help you create and maintain a consistent appearance and design for the Web site, such as ASP.NET themes and ASP.NET master pages. These features can be used early in the site-development process to provide a consistent look for the Web site.
ASP.NET themes define the appearance of pages and controls in the Web site. An ASP.NET theme can include skin files, which define property settings for ASP.NET Web server controls., A theme can also include and cascading style sheet files (.css files) and graphics. By applying a theme, you can give the pages in the Web site a consistent appearance. When you create a theme or set of themes for a site early in the development process, you can apply these themes to each new page that you create. For more information about themes, see ASP.NET Themes and Skins.
ASP.NET master pages let you create a page layout (a master page) that you can apply to selected pages (content pages) in the Web site. Master pages can greatly simplify the task of creating a consistent look for your site. You can also nest master pages. For example, you can use nested master pages to create one master layout for the whole site and another master layout for individual sections of a site. You can also use master pages with themes. For more information about master pages, see ASP.NET Master Pages and Nested ASP.NET Master Pages.
HTTP is a stateless protocol. Each request is serviced as it comes; after the request is processed, all the data is discarded. No state is maintained across requests even from the same client. However, for most Web applications, it is useful to maintain state across requests.
ASP.NET provides intrinsic state management functionality that enables you to store information between page requests, such as customer information or the contents of a shopping cart. You can save and manage application-specific, session-specific, page-specific, user-specific, and developer-defined information. ASP.NET has several forms of state management to select from, which includes using cookies, view state, session state, application state and profile properties. This information can be independent of any controls on the page.
When you plan a Web site, you should consider which forms of state management you will need. For more information see ASP.NET State Management Overview.
Often you can increase the performance of a Web site by storing data in memory that is accessed frequently and that requires significant processing time to create. For example, if your application processes large amounts of data by using complex logic and then returns the data as a report, it is efficient to avoid recreating the report every time that a user requests it. Similarly, if your application includes a page that processes complex data but the page is updated only infrequently, it is inefficient for the server to re-create that page on every request.
The ASP.NET cache is a general-purpose cache facility for Web sites. It provides a simple interface for caching and a more advanced interface that exposes expiration and change dependency services. To help you increase application performance in these situations, ASP.NET provides two caching mechanisms. The first is application caching, which enables you to cache data that you generate, such as a DataSet or a custom report business object. The second is page output caching, which saves the output of page processing and reuses the output instead of re-processing the page when a user requests the page again. If the Web site design takes into consideration caching particular pages, you can create a more efficient Web site.
In addition to the security features of the .NET Framework, ASP.NET provides a security infrastructure for authenticating and authorizing user access as well as performing other security-related tasks. You can authenticate users by using Windows authentication supplied by IIS. Alternatively, you can manage authentication by using ASP.NET forms authentication and ASP.NET membership. Additionally, you can manage the authorization to access resources of the Web application by using Windows groups or by using a custom role database and ASP.NET roles. You can easily remove, add to, or replace these schemes depending on the needs of your application. For more information see the following topics:
ASP.NET always runs with a particular Windows identity so that you can secure your application by using Windows capabilities such as NTFS file system Access Control Lists (ACLs) and database permissions. For more information about the identity that ASP.NET runs under, see Configuring ASP.NET Process Identity and ASP.NET Impersonation.
The topics in this section are topics you should also consider before you begin coding a Web site. By incorporating the information in these topics in your planning, you can save time and make your site compliant to today's Web standards.
Accessibility programming is the process of designing and developing applications that work with a computer's operating system to provide for specific impairments, such as a limited range of motion or blindness. ASP.NET can help you create Web applications that can be accessed by people with disabilities. Accessible Web applications enable people to use assistive technologies, such as screen readers, to work with Web pages. Accessible Web applications have the following advantages:
They are usable by the widest possible audience.
They involve design principles that frequently benefit all users, not just those with disabilities.
They meet the requirements of many institutions that require all Web applications to be accessible.
By understanding accessibility guidelines and how ASP.NET can help you meet those guidelines, you can create applications that are easier for people that have disabilities to interact with. For more information about accessibility guidelines, see Accessibility in Visual Studio and ASP.NET.
Most of the time, ASP.NET controls render markup that creates pages that meet accessibility standards. They might also expose properties that you can set to make the pages accessible. However, sometimes ASP.NET controls render output that does not comply with all accessibility standards. For detailed information, see ASP.NET Controls and Accessibility.
Globalization and Localization
Globalization is the process of designing and developing applications that function for multiple cultures. Localization is the process of customizing your application for a given culture and locale. If you create Web pages that will be read by speakers of different languages, you must enable readers to view the page in their own language. ASP.NET lets you create a page that can obtain content and other data based on the preferred language setting for the browser or the user's explicit choice of language. This content and other data is referred to as resources and such data can be stored in resource files or other sources. In the ASP.NET Web page, you configure controls to get their property values from resources. At run time, the resource expressions are replaced by resources from the appropriate resource file. For more information, see ASP.NET Web Page Resources Overview.
Building Individual Pages and Precompiling
Building a page or Web site is part of developing a site, and is intended to help you find compile-time errors that might occur anywhere in the site. Although building does compile the pages, it does not produce an assembly that you can deploy.
You can deploy a site without compiling it by copying all the files in the Web site to a production server. When users request pages from the production server, ASP.NET dynamically compiles the site, effectively performing the same steps that the build process does in Visual Studio. (ASP.NET caches the resulting output so that the pages do not have to be recompiled with each request.)
If you want to compile the site into assemblies and other files that you can deploy, you can publish the site. Publishing performs the same compilation steps that building does, but it saves the output into a folder and subfolders that you can in turn deploy to the production server.
For more information, ASP.NET Deployment Overview