|
|
Số người truy cập: 3.505.693
Số người trực tuyến: 75Trong đó có 1 thành viên: Trương Tam
|
|
|
| Trang chủ .NET Việt Nam
>
Bài viết
>
Theo ngôn ngữ
>
ASP.NET / ASP.NET 2.0 | ASP.NET Page Life Cycle | Dương Nguyễn .NET Việt Nam |
12:54' AM - Chủ nhật, 27/04/2008 | | IntroductionThis article describes the
life cycle of the page from the moment the URL is hit from the web
browser till the HTML code is generated and sent to the web browser.
Let us start by looking at some keywords that are involved in the life
cycle of the page.
Background IIS: IIS
(Internet Information Server) is a complete Web server that makes it
possible to quickly and easily deploy powerful Web sites and
applications. It is the default web server used with .NET. When a Web
server (for ASP.NET applications, typically IIS) receives a request, it
examines the file-name extension of the requested file, determines
which ISAPI extension should handle the request, and then passes the
request to the appropriate ISAPI extension. (By default, ASP.NET
handles file name extensions that have been mapped to it, such as
.aspx, .ascx, .ashx, and .asmx.)
Note: a.
If a file name extension has not been mapped to ASP.NET, ASP.NET will
not receive the request. It will be handled by the IIS. The requested
page/image/file is returned without any processing. b. If you create
a custom handler to service a particular file name extension, you must
map the extension to ASP.NET in IIS and also register the handler in
your application's Web.config file.
ASPNET_ISAPI.DLL:
This dll is the ISAPI extension provided with ASP.NET to process the
web page requests. IIS loads this dll and sends the page request to
this dll. This dll loads the HTTPRuntime for further processing. ASPNET_WP.EXE:
Each worker process (ASPNET_WP.EXE) contains an Application Pool. Each
Application Pool can contain any number of Applications. Application
Pool is also called as AppDomain. When a web page is requested, IIS
looks for the application pool under which the current application is
running and forwards the request to respective worker process.
HTTP Pipeline:
HTTP Pipeline is the general-purpose framework for server-side HTTP
programming that serves as the foundation for ASP.NET pages as well as
Web Services. All the stages involved from creating HTTP Runtime to
HTTP Handler is called HTTP Pipeline.
HTTP Runtime:
Each AppDomain has its own instance of the HttpRuntime class—the entry
point in the pipeline. The HttpRuntime object initializes a number of
internal objects that will help carry the request out. The HttpRuntime
creates the context for the request and fills it up with any HTTP
information specific to the request. The context is represented by an
instance of the HttpContext class. Another helper object that gets
created at such an early stage of the HTTP runtime setup is the text
writer—to contain the response text for the browser. The text writer is
an instance of the HttpWriter class and is the object that actually
buffers any text programmatically sent out by the code in the page.
Once the HTTP runtime is initialized, it finds an application object to
fulfill the request. The HttpRuntime object examines the request and
figures out which application it was sent to (from the pipeline's
perspective, a virtual directory is an application).
HTTP Context:
This is created by HTTP Puntime. The HttpContext class contains objects
that are specific to the current page request, such as the HttpRequest
and HttpResponse objects. You can use this class to share information
between pages. It can be accessed with Page.Context property in the
code.
HTTP Request: Provides access to the
current page request, including the request headers, cookies, client
certificate, query string, and so on. You can use this class to read
what the browser has sent. It can be accessed with Page.Request
property in the code.
HTTP Response: Provides
access to the output stream for the current page. You can use this
class to inject text into the page, to write cookies, and more. It can
be accessed with Page.Response property in the code.
HTTP Application:
An application object is an instance of the HttpApplication class—the
class behind the global.asax file. HTTPRuntime uses
HttpApplicationFactory to create the HTTPApplication object. The main
task accomplished by the HTTP application manager is finding out the
class that will actually handle the request. When the request is for an
.aspx resource, the handler is a page handler—namely, an instance of a
class that inherits from Page. The association between types of
resources and types of handlers is stored in the configuration file of
the application. More exactly, the default set of mappings is defined
in the <httpHandlers> section of the machine.config file.
However, the application can customize the list of its own HTTP
handlers in the local web.config file. The line below illustrates the
code that defines the HTTP handler for .aspx resources.
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>
HttpApplicationFactory:
Its main task consists of using the URL information to find a match
between the virtual directory of the URL and a pooled HttpApplication
object.
HTTP Module: An HTTP module is an
assembly that is called on every request that is made to your
application. HTTP modules are called as part of the ASP.NET request
pipeline and have access to life-cycle events throughout the request.
HTTP modules let you examine incoming and outgoing requests and take
action based on the request. They also let you examine the outgoing
response and modify it. ASP.NET uses modules to implement various
application features, which includes forms authentication, caching,
session state, and client script services. In each case, when those
services are enabled, the module is called as part of a request and
performs tasks that are outside the scope of any single page request.
Modules can consume application events and can raise events that can be
handled in the Global.asax file.
HTTP Handler:
An ASP.NET HTTP handler is the process that runs in response to a
request that is made to an ASP.NET Web application. The most common
handler is an ASP.NET page handler that processes .aspx files. When
users request an .aspx file, the request is processed by the page
handler. We can write our own handler and handler factory if we want to
handle the page request in a different manner.
Note:
HTTP modules differ from HTTP handlers. An HTTP handler returns a
response to a request that is identified by a file name extension or
family of file name extensions. In contrast, an HTTP module is invoked
for all requests and responses. It subscribes to event notifications in
the request pipeline and lets you run code in registered event
handlers. The tasks that a module is used for are general to an
application and to all requests for resources in the application. Life Cycle of Page 1. Web page request comes from browser. 2. IIS maps the ASP.NET file extensions to ASPNET_ISAPI.DLL, an ISAPI extension provided with ASP.NET. 3. ASPNET_ISAPI.DLL forwards the request to the ASP.NET worker process (ASPNET_WP.EXE or W3P.EXE). 4. ISAPI loads HTTPRuntime and passes the request to it. Thus, HTTP Pipelining has begun. 5. HTTPRuntime uses HttpApplicationFactory to either create or reuse the HTTPApplication object. 6. HTTPRuntime creates HTTPContext for the current request. HTTPContext internally maintains HTTPRequest and HTTPResponse. 7. HTTPRuntime also maps the HTTPContext to the HTTPApplication which handles the application level events. 8. HTTPApplication runs the HTTPModules for the page requests. 9. HTTPApplication creates HTTPHandler for the page request. This is the last stage of HTTPipelining. 10. HTTPHandlers are responsible to process request and generate corresponding response messages. 11. Once the request leaves the HTTPPipeline, page level events begin. 12.
Page Events are as follows: PreInit, Init, InitComplete, PreLoad, Load,
Control evetns (Postback events), Load Complete, PreRender,
SaveStateComplete, Render and Unload. 13. HTTPHandler generates the
response with the above events and sends back to the IIS which in turn
sends the response to the client browser.
 Events in the life cycle of page PreInit:
All the Pre and Post events are introduced as part of .NET Framework
2.0. As the name suggests this event is fired before the Init method is
fired. Most common functionalities implemented in this method include
a. Check the IsPostBack property b. Set the master page dynamically c. Set the theme property of the page dynamically d. Read or Set the profile property values. e. Re-create the dynamic controls Init:
This event is raised after all controls in the page are initialized and
any skin settings have been applied. This event is used to read or
initialize control properties. It can be used to register events for
some controls for which the events are not specified in the aspx page. Ex:
OnClick event of the Button can be registered in the Init rather than
specifying in the OnClick property of the Button in the aspx page. InitComplete: Use this event for processing tasks that require all initialization be complete. PreLoad:
Use this event if you need to perform processing on your page or
control before the Load event. After the Page raises this event, it
loads view state for itself and all controls, and then processes any
postback data included with the Request instance. Load:
The Page calls the OnLoad event method on the Page, then recursively
does the same for each child control, which does the same for each of
its child controls until the page and all controls are loaded. Use the
OnLoad event method to set properties in controls and establish
database connections. Control events: Use these
events to handle specific control events, such as a Button control's
Click event or a TextBox control's TextChanged event. LoadComplete: Use this event for tasks that require that all other controls on the page be loaded. PreRender:
This is the last event raised before the HTML code is generated for the
page. The PreRender event also occurs for each control on the page. Use
the event to make final changes to the contents of the page or its
controls. SaveStateComplete: Before this event
occurs, ViewState has been saved for the page and for all controls. Any
changes to the page or controls at this point will be ignored. Use this event perform tasks that require view state to be saved, but that do not make any changes to controls. Render:
This is the stage where the HTML code for the page is rendered. The
Page object calls the Render method of each control at this stage. All
ASP.NET Web server controls have a Render method that writes out the
control's markup that is sent to the browser. UnLoad:
This event occurs for each control and then for the page. In controls,
use this event to do final cleanup for specific controls, such as
closing control-specific database connections. For the page itself,
use this event to do final cleanup work, such as closing open files and
database connections, or finishing up logging or other request-specific
tasks. Theo
.NET Việt Nam Số lượt đọc:
601
-
Cập nhật lần cuối:
27/04/2008 12:54:42 AM | Working with XML and JavaScript 15/06/2008 01:11' AM As noted previously, Version 6 JavaScript browsers seem to be coming
together over the W3C DOM. Several key methods and properties in JavaScript
can help in getting information from an XML file. In the section, a very
simple XML file is used to demonstrate pulling data from XML into an HTML
page using JavaScript to parse (interpret) the XML file Xem mã của 1 trang aspnet 06/06/2008 07:03' PM Mô tả cấu trúc chung của 1 file aspnet
Giới thiệu ASP.NET 06/06/2008 07:01' PM ASP.NET là Active Server Pages .NET (.NET ở đây là .NET framework). Nói
đơn giản, ngắn và gọn thì ASP.NET là một công nghệ có tính cách mạng
dùng để phát triển các ứng dụng về mạng hiện nay cũng như trong tương
lai (ASP.NET is a revolutionary technology for developing web
applications) Xây dựng ứng dụng tin tức đơn giản bằng ASP.NET 2.0 06/06/2008 04:29' PM xây
dựng một ứng dụng quản lý tin tức đơn giản nhưng được phát triển trên
một mô hình chuẩn 3 lớp logíc. Loạt bài viết sẽ hướng dẫn bạn các bước
cơ bản trong quá trình phát triển một ứng dụng: từ bước phân tích yêu
cầu, phân tích chức năng, thiết kế hệ thống và hiện thực. Tổng quan,
loạt bài viết sẽ gồm các phần sau đây:
Giới thiệu ứng dụng tin tức, phân tích yêu cầu và chức năng Phân tích và thiết kế ứng dụng theo mô hình 3 lớp logíc Phát triển ứng dụng, phần quản lý Phát triển ứng dụng, phần trình bày tin tức Tổng kết và hướng phát triển
Mô hình MVC 01/06/2008 09:45' PM MVC, vấn đề khá trừu tượng, và cũng tương đối khá khó áp dụng. Sẵn có thread post hỏi về MVC tui đi tổng hợp lại 1 số cái, hy vọng có ích cho anh em.
Tăng tốc độ hiển thị web28/04/2008 05:22' PM- Tại server: Giảm thiểu những tính toán trên server, tối ưu CSDL, tạo bộ đệm, tối ưu chương trình...
- Đường truyền: Giảm thiểu dữ liệu truyền trên mạng bằng cách giảm
kích thước các file hình, giảm yêu cầu trao đổi dữ liệu giữa server và
client...
- Tại máy client: tối ưu mã html để trình duyệt hiển thị nhanh.
Với chiến lược trên, dưới đây là 10 thủ thuật có thể giúp tăng tốc độ hiển thị trang web.
Bài đã đăng: Aspect-Oriented Programming và bảo mật 25/04/2008 09:44' AM Aspect-Oriented
Programming (AOP) là một kiểu lập trình mới nhanh chóng thu hút được
các nhà phát triển trong giới CNTT. Một trong các lý do phổ biến là vì
nó được phân nhánh ra từ tính phổ biến của Java Spring framework, mọi
người bắt đầu hiểu những lợi ích trọng yếu mà AOP mang lại cho vấn đề
phát triển ứng dụng. Trong bài viết này chúng tôi muốn giới thiệu đến
đông bảo mọi người về AOP. Trước hết chúng ta hãy đặt câu hỏi AOP là
gì. 10 điều bạn nên biết về Silverlight25/04/2008 09:35' AMXây
dựng chiến lược Web là nhiệm vụ rất quan trọng đối với bất kỳ một doanh
nghiệp thành đạt nào. Tuy nhiên, việc thực hiện chiến lược đó với các
ứng dụng Internet phong phú không phải lúc nào cũng dễ dàng. Để giảm đi những khó khăn đó, gần đây như các bạn đã biết gã khổng lồ Microsoft đã đưa ra sản phẩm Silverlight,
một plug-in hoạt động trên đa nền tảng, đa trình duyệt cho các chuyên
gia phát triển ứng dụng. Plug-in này có thể cho phép phát triển các ứng
dụng một cách phong phú gồm có media, khả năng tương tác và hoạt ảnh.
Silverlight plug-in có thể làm việc trên các trình duyệt Internet
Explorer và Firefox trong Windows và Firefox cũng như trình duyệt
Safari trên hệ điều hành Mac. Building Web Parts (Part 2) 20/04/2008 04:01' PM In part one of this three-part series of articles, I discussed how to create Web Parts and how to configure them to look good and nice. But I have not really touched on the most important feature of Web Parts; that is, how to let users move the Web Parts from one zone to another. In this article, I will show you how to move Web Parts and how you can also configure Web Parts to make use of SQL Server 2000.
Building Web Parts (Part 1) 20/04/2008 03:59' PM
Websites today contain a wealth of information; so much that a poorly designed
site can easily overwhelm users. To better help users cope, portal websites
today (such as MSN) often organize their data into discrete units that support
a degree of personalization. Information is organized into standalone parts,
and users can rearrange those parts to suit their individual working styles.
Such personalization also lets users hide the parts that contain information in
which they have no interest. What's more, users can save their settings so that
the site will remember their preferences the next time they visit the site. In
ASP.NET 2.0, you can now build web portals that offer this kind of
modularization of information and personalization using the new Web Parts
framework. Hướng dẫn tạo website với Dynamic Theme 17/04/2008 12:34' AM Tình hình là site nào cũng cần change cái giao diện thường xuyên, nhìn cho đỡ nhàm, kiếm dc bài post lên cho anh em xem lun
MultiLanguages Website 17/04/2008 12:29' AM Hiện
nay, một website đa ngôn ngữ luôn là một yêu cầu không thể thiếu
trong cuộc cạnh tranh giữa các công ty thiết kế web. Có thể
mọi người nghĩ rằng thật khó để có thể làm một website có
nhiều ngôn ngữ như vây. Nhưng với Dot Net, bạn có thể tự làm
cho riêng mình một website đa ngôn ngữ, thật đơn giản.
Asp.net - Làm nổi bật 1 dòng trong DataGrid 02/04/2008 12:52' AM Đây
là một thủ thuật khá đơn giản và hữu ích khi ta làm việc với DataGrid
của Asp.net. Qua bài viết chúng ta có thể hiểu được cơ bản cách làm
việc của DataGrid cũng như cách dùng javascript trong các trang asp.net
|
|
|
|