Udostępnij za pośrednictwem


ASP.NET Overview

ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Framework. You can code your applications in any language compatible with the common language runtime (CLR), including Microsoft Visual Basic and C#. These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance, and so on.

If you want to try ASP.NET, you can install Visual Web Developer Express using the Microsoft Web Platform Installer, which is a free tool that makes it simple to download, install, and service components of the Microsoft Web Platform. These components include Visual Web Developer Express, Internet Information Services (IIS), SQL Server Express, and the .NET Framework. All of these are tools that you use to create ASP.NET Web applications. You can also use the Microsoft Web Platform Installer to install open-source ASP.NET and PHP Web applications.

This topic describes the following features of ASP.NET and of Visual Web Developer, the development environment for creating ASP.NET applications.

  • The Three Flavors of ASP.NET: Web Forms, MVC, and Web Pages

  • Visual Web Developer

  • ASP.NET Web Sites and ASP.NET Web Application Projects

  • ASP.NET API Reference

  • Page and Controls Framework

  • ASP.NET Compiler

  • Security Infrastructure

  • State-Management Facilities

  • ASP.NET Configuration

  • Health Monitoring and Performance Features

  • Debugging Support

  • Web Services Framework

  • Extensible Hosting Environment and Application Life-Cycle Management

  • Extensible Designer Environment

  • Web Applications Based on the MVC Pattern

  • ASP.NET Dynamic Data

The Three Flavors of ASP.NET: Web Forms, MVC, and Web Pages

ASP.NET offers three frameworks for creating web applications: ASP.NET Web Forms, ASP.NET MVC, and ASP.NET Web Pages. All three frameworks are stable and mature, and you can create great web applications with any of them.

Each framework targets a different audience or type of application. Which one you choose depends on a combination of your web development experience, what framework you’re most comfortable with, and which is the best fit for the type of application you’re creating. All three frameworks will be supported, updated, and improved in future releases of ASP.NET.

Here's an overview of each of the frameworks and some ideas for how to choose between them.

ASP.NET Web Forms (.aspx pages)

The Web Forms framework targets developers who prefer declarative and control-based programming, such as Microsoft Windows Forms (WinForms) and WPF/XAML/Silverlight. It offers a WYSIWYG designer-driven (drag-and-drop) development model, so it's popular with developers looking for a rapid application development (RAD) environment for web development. If you’re new to web programming and are familiar with the traditional Microsoft RAD client development tools (for example, for Visual Basic and Visual C#), you can quickly build a web application without having expertise in HTML and JavaScript.

In particular, the Web Forms model provides the following features:

  • An event model that exposes events which you can program like you would program a client application like WinForms or WPF.

  • Server controls that render HTML for you and that you can customize by setting properties and styles.

  • A rich assortment of controls for data access and data display.

  • Automatic preservation of state (data) between HTTP requests, which makes it easy for a programmer who is accustomed to client applications to learn how to create applications for the stateless web.

Web Forms works well for small teams of Web developers and designers who want to take advantage of the large number of components available for rapid application development. In general, creating a Web Forms application requires less programming effort than creating the same application by using the ASP.NET MVC framework. The components (the Page class, controls, and so on) are tightly integrated and usually require less code than ASP.NET MVC applications. However, Web Forms is not just for rapid application development. There are many complex commercial apps and app frameworks built on top of Web Forms.

Because a Web Forms page and the controls on the page automatically generate much of the markup that's sent to the browser, you don't have the kind of fine-grained control over the HTML that the other ASP.NET models offer. An event-driven, control-focused model hides some of the behavior of HTML and HTTP. For example, it's not always possible to specify exactly what markup might be generated by a control.

The Web Forms model doesn't lend itself as readily as ASP.NET MVC to patterns-based development, separation of concerns, and automated unit testing. If you want to write code factored that way, you can; it’s just not as automatic as it is in the ASP.NET MVC framework. The ASP.NET Web Forms MVP project shows an approach that facilitates separation of concerns and testability while maintaining the rapid development that Web Forms was built to deliver. As an example of this in action, Microsoft SharePoint is built using Web Forms MVP.

ASP.NET MVC

ASP.NET MVC targets developers who are interested in patterns and principles like test-driven development, separation of concerns, inversion of control (IoC), and dependency injection (DI). This framework encourages separating the business logic layer of a web application from its presentation layer.

By dividing the application into the model (M), views (V), and controllers (C), ASP.NET MVC can make it easier to manage complexity in larger applications. With ASP.NET MVC, you can have multiple teams working on a web site because the code for the business logic is separate from the code and markup for the presentation layer — developers can work on the business logic while designers work on the markup and JavaScript that is sent to the browser.

With ASP.NET MVC, you work more directly with HTML and HTTP than in Web Forms. Web Forms tends to hide some of that by mimicking the way you would program a WinForms or WPF application. For example, Web Forms can automatically preserve state between HTTP requests, but you have to code that explicitly in MVC. The MVC model enables you to take complete control over exactly what your application is doing and how it behaves in the web environment.

MVC was designed to be extensible, providing power developers the ability to customize the framework for their application needs. In addition, the ASP.NET MVC source code is available under an OSI license.

MVC 4 includes a feature that helps you develop HTTP services that reach a broad range of clients, including browsers and mobile devices. For more information, see Getting Started with ASP.NET Web API. MVC 4 also helps you develop single-page applications (SPAs) that use client-side JavaScript for responsive client interaction. For more information, see Single Page Application Overview.

For more information about ASP.NET MVC, see ASP.NET MVC.

ASP.NET Web Pages (.cshtml and .vbhtml files)

ASP.NET Web Pages targets developers who want a simple web development story, along the lines of PHP. In the Web Pages model, you create HTML pages and then add server-based code to the page in order to dynamically control how that markup is rendered. Web Pages is specifically designed to be a lightweight framework, and it's the easiest entry point into ASP.NET for people who know HTML but might not have broad programming experience — for example, students or hobbyists. It's also a good way for web developers who know PHP or similar frameworks to start using ASP.NET.

Like Web Forms, Web Pages is oriented toward rapid development. Web Pages provides components called helpers that you can add to pages and that let you use just a few lines of code to perform tasks that would either be tedious or complex. For example, there are helpers to display database data, add a Twitter feed, log in using Facebook, add maps to a page, and so on.

Web Pages provides a simpler approach than Web Forms. If you look at a .cshtml or .vbhtml file, you can generally think of the logic as executing top-to-bottom in the file, as you would with PHP, SHTML, etc. And because .cshtml and .vbhtml files are essentially HTML files that have additional ASP.NET code in them, they lend themselves easily to adding client-side functionality via JavaScript and jQuery.

For more information about ASP.NET Web Pages, see ASP.NET Web Pages on the ASP.NET web site.

General Notes

All three ASP.NET frameworks are based on the .NET Framework and share core functionality of .NET and of ASP.NET. For example, all three frameworks offer a login security model based around a membership API, and all three share the same facilities for managing requests, handling sessions, and so on that are part of the core ASP.NET functionality.

In addition, the three frameworks are not entirely independent, and choosing one does not preclude also using another. For example, MVC views are often written as .cshtml or .vbhtml files (using "Razor" syntax), which means they can take advantage of some of the Web Pages features like helpers. Since the frameworks can also coexist in the same web application, it's not uncommon to see individual components of an application written using different frameworks. For example, the bulk of a site might be written in MVC, but the data access portion of the site might be written using Web Forms because it’s such an easy framework in which to perform data access. In these cases, the developers choose the hybrid solution that plays to their strengths and makes their lives the easiest for their particular scenarios.

As of March 28, 2012, Microsoft has placed ASP.NET MVC 4, ASP.NET Web API, and ASP.NET Web Pages v2 (Razor syntax) under the open source Apache 2.0 license.  ASP.NET Web Forms is not included. For more information, see ASP.NET MVC, Web API, Razor and Open Source (ScottGu’s blog) and ASP.NET MVC 4, ASP.NET Web API and ASP.NET Web Pages v2 (Razor) now all open source with contributions (Scott Hanselman’s blog).

The remaining sections of this topic provide an overview of ASP.NET features that are common to all three ASP.NET frameworks or unique to Web Forms.

Visual Web Developer

Visual Web Developer is a full-featured development environment for creating ASP.NET Web applications. Visual Web Developer offers you the following features:

  • Web page design   A powerful Web page editor that includes WYSIWYG editing and an HTML editing mode with IntelliSense and validation.

  • Page design features   Consistent site layout with master pages and consistent page appearance with themes and skins.

  • Code editing   A code editor that enables you to write code for your dynamic Web pages in Visual Basic or C#. The code editor includes syntax coloration and IntelliSense.

  • Testing and Debugging   A local Web server for testing and a debugger that helps you find errors in your programs.

  • Deployment   Tools to automate typical tasks for deploying a Web application to a hosting server or a hosting provider.

For more information, see Visual Studio Web Development Content Map.

Testing and Debugging

Visual Web Developer provides an ideal environment in which to build Web sites and then publish them to a hosting site. Using the development tools in Visual Web Developer, you can develop ASP.NET Web pages on your own computer. Visual Web Developer includes a local Web server that provides all the features you need to test and debug ASP.NET Web pages, without requiring Internet Information Services (IIS) to be installed.

When your site is ready, you can publish it to the host computer using the built-in Copy Web tool, which transfers your files when you are ready to share them with others. Alternatively, you can precompile and deploy a Web site by using the Build Web Site command. The Build Web Site command runs the compiler over the entire Web site (not just the code files) and produces a Web site layout that you can deploy to a production server.

Note

The Build Web Site feature is not available in Visual Web Developer Express Edition.

Finally, you can take advantage of the built-in support for File Transfer Protocol (FTP). Using the FTP capabilities of Visual Web Developer, you can connect directly to the host computer and then create and edit files on the server.

ASP.NET Web Sites and ASP.NET Web Application Projects

Using Visual Studio, you can create different types of ASP.NET projects, which includes Web sites, Web applications, Web services, and AJAX server controls.

There is a difference between Web site projects and Web application projects. Some features work only with Web application projects, such as MVC and certain tools for automating Web deployment. Other features, such as Dynamic Data, work with both Web sites and Web application projects. For more information about the differences between Web application projects and Web site projects, see Web Application Projects versus Web Site Projects in Visual Studio.

ASP.NET API Reference

Some of the most important namespaces in the .NET Framework class library that pertain to ASP.NET are the following:

  • System.Web
    Provides classes and interfaces that enable browser-server communication. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request, the HttpResponse class, which manages HTTP output to the client, and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for cookie manipulation, file transfer, exception information, and output cache control.

  • System.Web.ApplicationServices
    Provides classes that provide access to ASP.NET forms authentication, roles, and profiles application services as Windows Communication Foundation (WCF) services.

  • System.Runtime.Caching
    Contains types that let you implement caching in .NET Framework applications.

  • System.Web.ClientServices
    Contains classes that support access to the ASP.NET login, roles, and profiles services from Windows-based applications.

  • System.Web.Configuration
    Contains classes that are used to programmatically manage ASP.NET configuration. (Most configuration settings can be made in XML files.)

  • System.Web.DynamicData
    Contains classes that provide the core functionality for ASP.NET dynamic data and extensibility features that let you customize dynamic data behavior.

  • System.Web.Handlers
    Contains HTTP handler classes that process HTTP requests to a Web server. (An ASP.NET Web Forms page -- .aspx file -- is a special form of an HTTP handler.)

  • System.Web.Management
    Contains classes and interfaces for managing and monitoring the health of Web applications.

  • System.Web.Profile
    Contains classes that are used to implement the ASP.NET user profile in Web server applications.

  • System.Web.Query.Dynamic
    Contains classes that are used to parse expressions from a LinqDataSource control into a Language-Integrated Query (LINQ).

  • System.Web.RegularExpressions
    Provides regular expressions that are used to parse ASP.NET files. All members of the System.Web.RegularExpressions namespace are descendants of the Regex class. (You typically do not have to parse ASP.NET pages yourself.)

  • System.Web.Routing
    Provides classes that are used with URL routing, which enables you to use URLs that do not map to a physical file.

  • System.Web.Script
    Contains classes that provide client-script resource information.

  • System.Web.Script.Services
    Provides attributes to customize Web service support for using Ajax functionality in ASP.NET.

  • System.Web.Security
    Contains classes that are used to implement ASP.NET security in Web server applications.

  • System.Web.Services
    Consists of the classes that enable you to create XML Web services using ASP.NET and XML Web service clients. XML Web services are applications that provide the ability to exchange messages in a loosely coupled environment using standard protocols such as HTTP, XML, XSD, SOAP, and WSDL. XML Web services let you build modular applications that are interoperable across a broad variety of implementations, platforms, and devices.

  • System.Web.SessionState
    Contains classes and interfaces that enable storage of data specific to a single client during a single browser session on the server. Session state data is used to give the client the appearance of a persistent connection with the application.

  • System.Web.UI
    Provides classes and interfaces that enable you to create ASP.NET server controls and ASP.NET Web pages for the user interface of your ASP.NET Web applications. This namespace includes the Control class, which provides all HTML server controls, Web server controls, and user controls with a common set of functionality. It also includes the Page control, which is generated automatically whenever a request is made for an .aspx file in an ASP.NET Web application. Also included are classes which provide the server controls with data-binding functionality, the ability to save the view state of a given control or page, and parsing functionality.

  • System.Web.UI.DataVisualization.Charting
    Contains types for the Chart Web server control.

  • System.Web.UI.Design.WebControls
    Contains classes that can be used to extend design-time support for Web server controls.

  • System.Web.UI.Design.WebControls.WebParts
    Contains classes that provide design-time support for controls derived from classes in the System.Web.UI.WebControls.WebParts namespace.

  • System.Web.UI.HtmlControls
    Contains a collection of classes that enable you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This enables you to programmatically control the HTML elements on a Web Forms page.

  • System.Web.UI.WebControls
    Contains classes that enable you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special-purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.

  • System.Web.UI.WebControls.WebParts
    Contains an integrated set of classes and interfaces for creating Web pages whose appearance and behavior can be modified (personalized) by end users. The user-defined settings for each page are saved for future browser sessions.

  • System.Web.Util
    Contains classes that enable callback methods to be run under the scope of a transaction and that enable work to be posted to separate threads.

  • ASP.NET MVC Reference
    This topic provides links to four namespaces that are used by the MVC framework.

For a complete list of .NET Framework namespaces, with links to API reference topics for them, see .NET Framework Class Library.

Page and Controls Framework

The ASP.NET Web Forms page and controls framework is a programming framework that runs on a Web server to dynamically produce and render ASP.NET Web pages. ASP.NET Web pages can be requested from any browser or client device, and ASP.NET renders markup (such as HTML) to the requesting browser. As a rule, you can use the same page for multiple browsers, because ASP.NET renders the appropriate markup for the browser making the request. However, you can design your ASP.NET Web page to target a specific browser and take advantage of the features of that browser.

ASP.NET Web Forms pages are completely object-oriented. Within ASP.NET Web forms pages you can work with HTML elements using properties, methods, and events. The ASP.NET page framework removes the implementation details of the separation of client and server inherent in Web-based applications by presenting a unified model for responding to client events in code that runs at the server. The framework also automatically maintains the state of a page and the controls on that page during the page processing life cycle. For more information see ASP.NET Web Forms Pages Overview.

The ASP.NET page and controls framework also enables you to encapsulate common UI functionality in easy-to-use, reusable controls. Controls are written once, can be used in many pages, and are integrated into the ASP.NET Web page that they are placed in during rendering.

The ASP.NET page and controls framework also provides features to control the overall look and feel of your Web site via themes and skins. You can define themes and skins and then apply them at a page level or at a control level. For more information, see ASP.NET Themes and Skins.

In addition to themes, you can define master pages that you use to create a consistent layout for the pages in your application. A single master page defines the layout and standard behavior that you want for all the pages (or a group of pages) in your application. You can then create individual content pages that contain the page-specific content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page. For more information see ASP.NET Master Pages.

The ASP.NET page framework also enables you to define the pattern for URLs that will be used in your site. This helps with search engine optimization (SEO) and makes URLs more user-friendly. For more information, see ASP.NET Routing.

The ASP.NET page and control framework is designed to generate HTML that conforms to accessibility guidelines. For more information, see Accessibility in Visual Studio and ASP.NET.

ASP.NET Compiler

All ASP.NET code is compiled, which enables strong typing, performance optimizations, and early binding, among other benefits. Once the code has been compiled, the common language runtime further compiles ASP.NET code to native code, providing improved performance.

ASP.NET includes a compiler that will compile all your application components including pages and controls into an assembly that the ASP.NET hosting environment can then use to service user requests. For more information, see ASP.NET Compilation Overview.

Security Infrastructure

In addition to the security features of .NET, ASP.NET provides an advanced security infrastructure for authenticating and authorizing user access as well as performing other security-related tasks. You can authenticate users using Windows authentication supplied by IIS, or you can manage authentication using your own user database using ASP.NET forms authentication and ASP.NET membership. Additionally, you can manage the authorization to the capabilities and information of your Web application using Windows groups or your own custom role database using ASP.NET roles. You can easily remove, add to, or replace these schemes depending upon the needs of your application. For more information, see the following topics:

ASP.NET always runs with a particular Windows identity so you can secure your application using Windows capabilities such as NTFS Access Control Lists (ACLs), database permissions, and so on. For more information about the identity of ASP.NET, see Configuring ASP.NET Process Identity and ASP.NET Impersonation.

Web Forms State-Management Facilities

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. This information can be independent of any controls on the page.

ASP.NET offers distributed state facilities, which enable you to manage state information across multiple instances of the same application on one computer or on several computers. For more information, see ASP.NET State Management Overview.

ASP.NET Configuration

ASP.NET applications use a configuration system that enables you to define configuration settings for your Web server, for a Web site, or for individual applications. You can make configuration settings at the time your ASP.NET applications are deployed and can add or revise configuration settings at any time with minimal effect on operational Web applications and servers. ASP.NET configuration settings are stored in XML-based files. Because these XML files are text files, it is simple to make configuration changes to your Web applications. You can extend the configuration scheme to suit your requirements. For more information, see ASP.NET Configuration Overview.

Health Monitoring and Performance Features

ASP.NET includes features that enable you to monitor health and performance of your ASP.NET application. ASP.NET health monitoring enables reporting of key events that provide information about the health of an application and about error conditions. These events show a combination of diagnostics and monitoring characteristics and offer a high degree of flexibility in terms of what is logged and how it is logged. For more information, see ASP.NET Health Monitoring Overview.

ASP.NET supports two groups of performance counters available to your applications:

  • The ASP.NET system performance counter group

  • The ASP.NET application performance counter group

For more information, see Monitoring ASP.NET Application Performance.

Debugging Support

ASP.NET takes advantage of the run-time debugging infrastructure to provide cross-language and cross-computer debugging support. You can debug both managed and unmanaged objects, in addition to all languages supported by the common language runtime and script languages. For details, see ASP.NET Debugging.

In addition, the ASP.NET page framework provides a trace mode that enables you to insert instrumentation messages into your ASP.NET Web pages. For more information, see ASP.NET Tracing Overview.

Web Services Framework

ASP.NET supports Web services using Windows Communication Foundation. A Web service is a component that contains business functionality that enables applications to exchange information across firewalls by using standards like HTTP and XML messaging. Web services are not tied to a particular component technology or object-calling convention. As a result, programs written in any language, using any component model, and running on any operating system can access Web services. For more information, see Windows Communication Foundation Services and WCF Data Services in Visual Studio.

Extensible Hosting Environment and Application Life-Cycle Management

ASP.NET includes an extensible hosting environment that controls the life cycle of an application from when a user first accesses a resource (such as a page) in the application to the point at which the application is shut down. While ASP.NET relies on a Web server (IIS) as an application host, ASP.NET provides much of the hosting functionality itself. The architecture of ASP.NET enables you to respond to application events and create custom HTTP handlers and HTTP modules. For more information, see ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0.

Web Forms Extensible Designer Environment

ASP.NET includes enhanced support for creating designers for Web server controls for use with a visual design tool such as Visual Studio. Designers enable you to build a design-time user interface for a control, so that developers can configure your control's properties and content in the visual design tool. For more information, see ASP.NET Control Designers Overview.

ASP.NET Dynamic Data Scaffolding

ASP.NET Dynamic Data scaffolding is a framework built on ASP.NET Web Forms that lets you create data-driven ASP.NET Web applications easily. It does this by automatically discovering data-model metadata at run time and deriving UI behavior from it. A scaffolding framework provides a functional Web site for viewing and editing data. You can easily customize the scaffolding framework by changing elements or creating new ones to override the default behavior. Existing applications can easily integrate scaffolding elements together with ASP.NET pages.

You will find that you can get applications up and running more easily and with less code than before. At the same time, you can add custom features to ASP.NET Dynamic Data to accommodate your own requirements. For more information, see ASP.NET Dynamic Data.

See Also

Concepts

ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0

ASP.NET Web Forms Pages Overview

Other Resources

Visual Studio Web Development Content Map