2023年全國碩士研究生考試考研英語一試題真題(含答案詳解+作文范文)_第1頁
已閱讀1頁,還剩10頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、<p>  附錄 1 英文原文</p><p>  Introduction to ASP.NET Pages and Inline Code and Share[10]</p><p>  The ASP.NET Web Forms page framework is a scalable common language runtime programming model t

2、hat can be used on the server to dynamically generate Web pages. Intended as a logical evolution of ASP (ASP.NET provides syntax compatibility with existing pages), the ASP.NET page framework has been specifically design

3、ed to address a number of key deficiencies in the previous model. In particular, it provides the ability to create and use reusable UI controls that can encapsulate common functionality </p><p>  ASP.NET pag

4、es are text files with an .htm file name extension. Pages consist of code and markup and are dynamically compiled and executed on the server to produce a rendering to the requesting client browser (or device). They can b

5、e deployed throughout an IIS virtual root directory tree. When a browser client requests .htm resources, the ASP.NET runtime parses and compiles the target file into a .NET Framework class. This class can then be used to

6、 dynamically process incoming requests. (Note tha</p><p>  ASP.NET provides syntax compatibility with existing ASP pages. This includes support for <% %> code render blocks that can be intermixed with

7、HTML content within an .htm file. These code blocks execute in a top-down manner at page render time. The below example demonstrates how <% %> render blocks can be used to loop over an HTML block (increasing the

8、 font size each time): Important: Unlike with ASP, the code used within the above <% %> blocks is actually compiled--not interpreted using a</p><p>  In addition to code and markup, ASP.NET pages c

9、an contain server controls, which are programmable server-side objects that typically represent a UI element in the page, such as a textbox or image. Server controls participate in the execution of the page and produce t

10、heir own markup rendering to the client. The principle advantage of server controls is that they enable developers to get complex rendering and behaviors from simple building-block components, dramatically reducing the a

11、mount of code</p><p>  Each ASP.NET server control is capable of exposing an object model containing properties, methods, and events. ASP.NET developers can use this object model to cleanly modify and intera

12、ct with the page. Note, however, how much cleaner and easier the code is in this new server-control-based version. As we will see later in the tutorial, the ASP.NET page Framework also exposes a variety of page-lev

13、el events that you can handle to write code to execute a specific time during the processing of </p><p>  The example below demonstrates a simple ASP.NET page with three server controls, a TextBox, Button, a

14、nd a Label. Initially these controls just render their HTML form equivalents. However, when a value is typed in the TextBox and the Button is clicked on the client, the page posts back to the server and the page handles

15、this click event in the code of the page, dynamically updating the Text property of the Label control. The page then re-renders to reflect the updated text. This simple example de</p><p>  Note that in the p

16、receding example the event handler for the Button was located between <script></script> tags in the same page containing the server controls. ASP.NET calls this type of page programming code-inline, and it is

17、 very useful when you want to maintain your code and presentation logic in a single file. However, ASP.NET also supports another way to factor your code and presentation content, called the code-behind model. When using

18、code-behind, the code for handling events is located i</p><p>  ASP.NET 2.0 introduces an improved runtime for code-behind pages that simplifies the connections between the page and code. In this new code-be

19、hind model, the page is declared as a partial class, which enables both the page and code files to be compiled into a single class at runtime. The page code refers to the code-behind file in the CodeFile attribute of the

20、 <%@ Page %> directive, specifying the class name in the Inherits attribute. Note that members of the code behind class must be either pu</p><p>  The advantage of the simplified code-behind model over

21、 previous versions is that you do not need to maintain separate declarations of server control variables in the code-behind class. Using partial classes (new in 2.0) allows the server control IDs of the ASPX page to be a

22、ccessed directly in the code-behind file. This greatly simplifies the maintenance of code-behind pages.</p><p>  Although you can place code inside each page within your site (using the inline or code-behind

23、 separation models described in the previous section), there are times when you will want to share code across several pages in your site. It would be inefficient and difficult to maintain this code by copying it to ever

24、y page that needs it. Fortunately, ASP.NET provides several convenient ways to make code accessible to all pages in an application.</p><p>  Just as pages can be compiled dynamically at runtime, so can arbit

25、rary code files (for example .cs or .vb files). ASP.NET 2.0 introduces the App_Code directory, which can contain standalone files that contain code to be shared across several pages in your application. Unlike ASP.NET 1.

26、x, which required these files to be precompiled to the Bin directory, any code files in the App_Code directory will be dynamically compiled at runtime and made available to the application. It is possible to place </p

27、><p>  By default, the App_Code directory can only contain files of the same language. However, you may partition the App_Code directory into subdirectories (each containing files of the same language) in order

28、 to contain multiple languages under the App_Code directory. To do this, you need to register each subdirectory in the Web.config file for the application. </p><p>  <configuration></p><p>

29、;  <system.web></p><p>  <compilation></p><p>  <codeSubDirectories></p><p>  <add directoryName="Subdirectory"/></p><p>  </codeSu

30、bDirectories></p><p>  </compilation></p><p>  </system.web></p><p>  </configuration></p><p>  Supported in ASP.NET version 1, the Bin directory i

31、s like the Code directory, except it can contain precompiled assemblies. This is useful when you need to use code that is possibly written by someone other than yourself, where you don't have access to the source cod

32、e (VB or C# file) but you have a compiled DLL instead. Simply place the assembly in the Bin directory to make it available to your site. By default, all assemblies in the Bin directory are automatically loaded in the app

33、 and made acc</p><p>  The .NET Framework 2.0 includes a number of assemblies that represent the various parts of the Framework. These assemblies are stored in the global assembly cache, which is a versioned

34、 repository of assemblies made available to all applications on the machine (not just a specific application, as is the case with Bin and App_Code). Several assemblies in the Framework are automatically made available to

35、 ASP.NET applications. You can register additional assemblies by registration in a Web.config fi</p><p>  <configuration></p><p>  <compilation></p><p>  <assemblies&

36、gt;</p><p>  <add assembly="System.Data, Version=1.0.2411.0, </p><p>  Culture=neutral, </p><p>  PublicKeyToken=b77a5c561934e089"/></p><p>  </assem

37、blies></p><p>  </compilation></p><p>  </configuration></p><p>  附錄 2 中文譯文</p><p>  ASP.NET介紹以及內(nèi)聯(lián)代碼和共享</p><p>  ASP.NET Web 窗體頁框架是一種可用于在服務(wù)

38、器上動(dòng)態(tài)生成網(wǎng)頁的可伸縮公共語言運(yùn)行庫編程模型。作為ASP的繼承和發(fā)展,ASP.NET 頁框架消除了以前ASP中存在的缺陷。尤其是,它提供了創(chuàng)建和使用可封裝常用功能的可重用用戶界面控件的能力,從而減少了頁開發(fā)人員編寫代碼的數(shù)量,它還為開發(fā)人員提供了清晰、有序地構(gòu)造頁面的能力,以及可使開發(fā)工具真正做到所見即所得的功能。本部分的快速入門提供對某些基本 ASP.NET 頁功能的高級代碼演練,后面部分的快速入門將深入介紹更具體的細(xì)節(jié)。</

39、p><p>  ASP.NET 頁是采用 .aspx 文件擴(kuò)展名的文本文件。頁由代碼和HTML組成,并在服務(wù)器上動(dòng)態(tài)編譯和執(zhí)行以呈現(xiàn)給發(fā)出請求的客戶端瀏覽器。它們放在IIS服務(wù)器上的虛擬目錄中。當(dāng)瀏覽器客戶端請求 .aspx 資源時(shí),ASP.NET 運(yùn)行庫會(huì)對目標(biāo)文件進(jìn)行分析并將其編譯為 .NET Framework 類。然后,可以使用此類動(dòng)態(tài)處理傳入的請求。</p><p>  只需獲取現(xiàn)有

40、 HTML 文件并將該文件的文件擴(kuò)展名更改為 .aspx,就可以創(chuàng)建一個(gè) ASP.NET 頁。例如,下面的示例演示了一個(gè)簡單 HTML 頁,它收集用戶名和類別首選項(xiàng),然后在單擊某一按鈕時(shí)執(zhí)行窗體回發(fā),發(fā)送至發(fā)起請求的頁。</p><p>  重要事項(xiàng):注意在單擊“Lookup”(查找)按鈕時(shí),不會(huì)發(fā)生任何操作。這是因?yàn)?.aspx 文件只包含靜態(tài) HTML(不包含動(dòng)態(tài)內(nèi)容)。因此,相同的 HTML 在每次發(fā)送到頁

41、時(shí)都會(huì)被發(fā)送回客戶端,這會(huì)導(dǎo)致在請求之間窗體字段(文本框和下拉列表)的內(nèi)容丟失。 </p><p>  ASP.NET 提供了與現(xiàn)有 ASP 頁的語法兼容性。這包括對 <% %> 代碼呈現(xiàn)塊的支持,這些塊可以與 .aspx 文件中的 HTML 內(nèi)容混用。在呈現(xiàn)頁時(shí),這些代碼塊以從上至下的方式執(zhí)行。</p><p>  重要事項(xiàng):與 ASP 不同,上述 <% %> 塊

42、中使用的代碼實(shí)際上是使用腳本引擎編譯的,而不是解釋。這可以提高運(yùn)行時(shí)執(zhí)行性能。 </p><p>  ASP.NET 頁開發(fā)人員可利用 <% %> 代碼塊動(dòng)態(tài)修改 HTML 輸出,就好像目前可使用 ASP 進(jìn)行修改一樣。例如,下面的示例演示如何使用 <% %> 代碼塊解釋從客戶端發(fā)回的請求。</p><p>  重要事項(xiàng):盡管 <% %> 代碼塊提供了一

43、種對從 ASP.NET 頁返回的文本輸出進(jìn)行自定義操作的強(qiáng)大方法,但這些代碼塊未提供一種清晰的 HTML 編程模型。正如上述示例所闡述的那樣,只使用 <% %> 代碼塊的開發(fā)人員必須自定義管理往返過程之間的頁狀態(tài)并自定義解釋發(fā)送的值。 </p><p>  除了代碼和標(biāo)記之外,ASP.NET 頁還可以包含服務(wù)器控件,這些控件是可編程的服務(wù)器端對象,通常表示頁中的用戶界面元素,如文本框或圖像等。服務(wù)器控

44、件參與頁的執(zhí)行,并生成它們自己的標(biāo)記呈現(xiàn)給客戶端。服務(wù)器控件的主要優(yōu)點(diǎn)在于它們使開發(fā)人員可以從簡單的構(gòu)造塊組件獲取復(fù)雜的呈現(xiàn)和行為,從而大幅度減少了生成動(dòng)態(tài)網(wǎng)頁所需的代碼量。服務(wù)器控件的另一個(gè)優(yōu)點(diǎn)在于可以很容易地自定義其呈現(xiàn)或行為。服務(wù)器控件公開可以聲明方式(通過標(biāo)記)或編程方式(通過代碼)設(shè)置的屬性。服務(wù)器控件(和頁本身)還公開了一些事件,開發(fā)人員可以處理這些事件以在頁執(zhí)行期間執(zhí)行特定的操作或響應(yīng)將頁發(fā)回服務(wù)器的客戶端操作(“回發(fā)”)

45、。此外,服務(wù)器控件還簡化了在往返于服務(wù)器的過程中保留狀態(tài)的問題,自動(dòng)在連續(xù)回發(fā)之間保留其值。 </p><p>  服務(wù)器控件在 .aspx 文件中是使用自定義標(biāo)記或包含 runat="server" 屬性值的內(nèi)部 HTML 標(biāo)記聲明的。內(nèi)部 HTML 標(biāo)記由 System.Web.UI.HtmlControls 命名空間中的某個(gè)控件處理。未顯式映射到這些控件之一的任何標(biāo)記都將被指定為 Sys

46、tem.Web.UI.HtmlControls.HtmlGenericControl 類型。 </p><p>  下面的示例使用以下四個(gè)服務(wù)器控件:<form runat=server>、<asp:textbox runat=server>、 <asp:dropdownlist runat=server> 和 <asp:button runat=server>。在

47、運(yùn)行時(shí),這些服務(wù)器控件將自動(dòng)生成 HTML 內(nèi)容。 </p><p>  重要事項(xiàng):注意,在到服務(wù)器的往返過程之間,這些服務(wù)器控件自動(dòng)保留客戶端輸入的任何值。此控件狀態(tài)不存儲(chǔ)在服務(wù)器上(而是存儲(chǔ)在往返于請求之間的 <input type="hidden"> 窗體字段中)。另外,還須注意不需要客戶端腳本。 </p><p>  除支持標(biāo)準(zhǔn) HTML 輸入控件之

48、外,ASP.NET 還使開發(fā)人員能夠在他們的頁上利用更豐富的自定義控件。例如,下面的示例演示如何使用 <asp:adrotator> 控件在頁上動(dòng)態(tài)顯示循環(huán)廣告。</p><p>  重要事項(xiàng):所有內(nèi)置服務(wù)器控件的詳細(xì)列表可在本快速入門的“控件參考” 部分中找到。 </p><p>  每個(gè) ASP.NET 服務(wù)器控件都可以公開包含屬性、方法和事件的對象模型。ASP.NET 開

49、發(fā)人員可以使用此對象模型清晰地修改頁以及與頁進(jìn)行交互。 </p><p>  下面的示例演示 ASP.NET 頁開發(fā)人員可如何處理 <asp:button runat=server> 控件中的 OnClick 事件以操作 <asp:label runat=server> 控件的 Text 屬性。 </p><p>  ASP.NET 提供了可以組織頁中代碼的兩種方法

50、。 </p><p>  下面的代碼示例演示一個(gè)包含以下三個(gè)服務(wù)器控件的簡單 ASP.NET 頁:TextBox、Button 和 Label。最初,這些控件只呈現(xiàn)其 HTML 窗體等效項(xiàng)。但是,當(dāng)客戶端在 TextBox 中鍵入了一個(gè)值并單擊了 Button 后,該頁會(huì)回發(fā)到服務(wù)器,然后該頁使用頁中的代碼處理此單擊事件,動(dòng)態(tài)地更新 Label 控件的 Text 屬性。然后,該頁將重新呈現(xiàn)以反映更新后的文本。此簡

51、單示例演示了服務(wù)器控件模型內(nèi)在的基本機(jī)制,該模型使 ASP.NET 成為最容易學(xué)習(xí)和掌握的 Web 編程模型之一。 </p><p>  ASP.NET 調(diào)用此類型的頁編程“代碼內(nèi)聯(lián)”,如果您要在一個(gè)文件中維護(hù)您的代碼和表示邏輯,則該方法十分有用。但 ASP.NET 還支持另一種分解代碼和表示內(nèi)容的方法,該方法稱為“代碼隱藏”模型。在使用代碼隱藏時(shí),處理事件的代碼所在的文件與包含服務(wù)器控件和標(biāo)記的頁在物理上分開。

52、在您需要分別維護(hù)代碼和內(nèi)容(如有多個(gè)人員參與創(chuàng)建應(yīng)用程序工作)時(shí),這種將代碼和內(nèi)容清楚區(qū)分的方法十分有用。在團(tuán)隊(duì)項(xiàng)目中,設(shè)計(jì)人員通常負(fù)責(zé)應(yīng)用程序的用戶界面部分的工作,而開發(fā)人員則負(fù)責(zé)行為或代碼部分。代碼隱藏模型非常適用于此類環(huán)境。 </p><p>  ASP.NET 2.0 為代碼隱藏頁引入了一個(gè)改進(jìn)的運(yùn)行庫,該庫可簡化頁和代碼之間的連接。在這一新的代碼隱藏模型中,頁被聲明為分部類,這使得頁和代碼文件可在運(yùn)行時(shí)

53、編譯為一個(gè)類。通過在 Inherits 屬性中指定類名,頁代碼使用 <%@ Page %> 指令的 CodeFile 屬性來引用代碼隱藏文件。請注意,代碼隱藏類的成員必須是公共或受保護(hù)的成員(不能為私有成員)。</p><p>  與以前版本相比,這種簡化的代碼隱藏模型的好處在于無需維護(hù)代碼隱藏類中服務(wù)器控件變量的各個(gè)不同的聲明。使用分部類(2.0 中的新增功能)可在代碼隱藏文件中直接訪問 ASPX

54、頁的服務(wù)器控件 ID。這極大地簡化了代碼隱藏頁的維護(hù)工作。</p><p>  盡管可以將代碼放在站點(diǎn)的每個(gè)頁上(使用上一節(jié)中所述的內(nèi)聯(lián)或代碼隱藏分離模型),但有時(shí)您將希望在站點(diǎn)中的多個(gè)頁之間共享代碼。將這些代碼復(fù)制到需要它們的每個(gè)頁上,這種做法既低效又使代碼難以維護(hù)。幸運(yùn)的是,ASP.NET 提供了幾種簡單的方法,使應(yīng)用程序中的所有頁都可以訪問代碼。 </p><p>  與頁可在運(yùn)行時(shí)

55、動(dòng)態(tài)編譯一樣,任意代碼文件(例如,.cs 或 .vb 文件)也可以在運(yùn)行時(shí)動(dòng)態(tài)編譯。ASP.NET 2.0 引入了 App_Code 目錄,該目錄可以包含一些獨(dú)立文件,這些文件包含要在應(yīng)用程序中的多個(gè)頁之間共享的代碼。與 ASP.NET 1.x 不同(1.x 需要將這些文件預(yù)編譯到 Bin 目錄),App_Code 目錄中的所有代碼文件都將在運(yùn)行時(shí)動(dòng)態(tài)編譯,然后提供給應(yīng)用程序??梢栽?App_Code 目錄下放置多種語言的文件,前提是將

56、這些文件劃分到各子目錄中(在 Web.config 中用特定語言注冊這些子目錄)。下面的示例演示如何使用 App_Code 目錄包含一個(gè)從頁調(diào)用的類文件。 </p><p>  默認(rèn)情況下,App_Code 目錄只能包含同一種語言的文件。但可以將 App_Code 目錄劃分為若干子目錄(每個(gè)子目錄包含同一語言的文件)以便可以在 App_Code 目錄下包含多種語言。為此,需要在應(yīng)用程序的 Web.config 文

57、件中注冊每個(gè)子目錄。</p><p>  <configuration></p><p>  <system.web></p><p>  <compilation></p><p>  <codeSubDirectories></p><p>  <add dir

58、ectoryName="Subdirectory"/></p><p>  </codeSubDirectories></p><p>  </compilation></p><p>  </system.web></p><p>  </configuration>

59、</p><p>  在 ASP.NET 版本 中支持 Bin 目錄,該目錄類似于 Code 目錄,不同的是它可以包含預(yù)編譯的程序集。如果需要使用其他人編寫的代碼,則此目錄就很有用了,您不用訪問源代碼(VB 或 C# 文件)就可以得到編譯后的 DLL。主要在你的程序中將該DLL作為引用添加到你的工程。默認(rèn)情況下,Bin 目錄中的所有程序集都自動(dòng)加載到應(yīng)用程序中,然后可供各頁訪問。您可能需要使用頁最上方的 @Im

60、port 指令從 Bin 目錄的程序集中導(dǎo)入特定的命名空間。<@ Import Namespace="MyCustomNamespace" ></p><p>  .NET Framework 2.0 提供了表示 Framework 的各個(gè)部件的大量類庫程序集。這些程序集存儲(chǔ)在全局程序集緩存中,該緩存是程序集的版本化存儲(chǔ)庫,可供計(jì)算機(jī)上的所有應(yīng)用程序使用。Framework 中的多

61、個(gè)程序集都可自動(dòng)提供給 ASP.NET 應(yīng)用程序。通過在應(yīng)用程序的 Web.config 文件中注冊,并且可以注冊更多的程序集。 </p><p>  <configuration></p><p>  <compilation></p><p>  <assemblies></p><p>  <a

62、dd assembly="System.Data, Version=1.0.2411.0, </p><p>  Culture=neutral, </p><p>  PublicKeyToken=b77a5c561934e089"/></p><p>  </assemblies></p><p> 

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論