2012年10月25日 星期四

WCF 簡介

Windows Communication Foundation
WCF 它是微軟於 .NET 3.0 開始加入的一組用於通訊 (Communication) 的應用程式開發介面。 主要功能在開發以服務為導向的分散式系統。

XML Web Service

Web Service 是一種以服務為導向的架構技術,透過標準的 Web 協議提供服務,目的是讓不同平台的應用服務可以互動操作。 根據W3C的定義,Web服務(Web service)應當是一個軟體系統,用以支持網路間不同機器的互動操作。 網路服務通常是許多應用程式介面(API)所組成的,它們透過網路上的遠端伺服機,執行客戶所提交服務的請求。

Web Service 透過 WSDL 文件提供該服務的定義描述。 Web Service 採用 SOAP 協議進行 XML 格式的訊息傳遞。 SOAP 協議必須繫結到某個傳輸協定,這個傳輸協定通常是 http, https, 但也可以是 stmp 或 xmpp.

Client-Side Script

JavaScript

It is important to note that JavaScript is not new.
It is also not really Java.
It is a C-based scripting language invented by Netscape to add client scripting capabilities to a browser.
It is now supported as part of every major browser on the market.
The actual language is controlled and managed by a standards body, the European Computer Manufacturers Association (ECMA).
Because it is widely deployed and offers developers the ability to write code on the client, it has become increasingly popular.
This was especially true once features for communicating between the client script and server code using JSON and XML became prevalent.

Ajax Web Forms

什麼是 AJAX

AJAX 為「Asynchronous JavaScript and XML」(非同步的JavaScript與XML技術),是一種廣泛應用在瀏覽器的網頁開發技術。 Ajax 是多項技術的綜合應用,其概念是由 Jesse James Garrett 所提出。 利用這項技術將可增進網頁的回應能力以提供使用者與主機端的互動功能,以達到網頁非同步處理

AJAX 網頁是屬於用戶端(展示層)的技術,在用戶端的瀏覽器必須使用 JavaScript 的 XMLHttpRequest 物件,送出非同步的 Http Request, 此時只會將指定的欄位資料傳送至伺服器端,而網頁的其他資料並不會進行回傳(PostBack),接著再透過 Http Response 方式將更新後的執行結果下載至用戶端的瀏覽器。 最後透過 JavaScript 將回應的執行結果以背景執行的方式寫回 DHTML 或 DOM(DocumentObject Model) 指定的標籤區塊,此時指定的區塊即會進行更新。由於傳送和接收資料是屬於非同步的模式,因此使用者可以在不換頁的情形下繼續在網頁上進行任何操作。

資料繫結控制項(Simple)

簡單的資料繫結控制項包含: DropDownListListBoxCheckBoxListRadioButtonListBulletedList

資料來源控制項(1)

透過 ADO.NET 我們可以利用程式碼建立資料庫連線以存取資料,這些程式碼通常會被建立在抽象的 DAL 或 BLL 層。 若須求只有簡單的建立連線與存取資料,我們也可以透過資料來源控制項來實現,而不用使用 ADO.NET 。 它可以存取的對象包括 objects, XML, and databases 。

特殊 Server Controls

通用 Server Controls

通用型(common)的伺服器控制項,指的是 LabelTextBoxButtonCheckBoxRadioButton 這類較基本功能的控制項。

認識 Server Controls

Web server controls provide more functionality and a more consistent programming model than HTML server controls. Web server controls are based on .NET Framework classes, typically inherited from the WebControl class. ASP.NET renders web server controls as standardized HTML. In other words, if you use the Button web server control, ASP.NET renders it using the <button> HTML markup tag.

2012年10月17日 星期三

行動網頁

Tracing 網站

當問題不容易在 Visual Studion 中發現時,就可以利用 ASP.NET 提供網頁監測功能進行追蹤。 要使用網頁監測功能,只要透過設定將「追蹤」功能啟用即可。 它可以針對個別網頁或整個網站進行追蹤,例如:記錄使用者資訊,網頁執行時間,錯誤訊息等等。

Debugging 網站

Configuring ASP.NET for Debugging

To configure ASP.NET for debugging, there are two areas where you set this information: the project's property page and the Web.config file.

使用快取

Caching 是 ASP.NET 的一種機制,由 Cache 類別實作,用來提升網頁的效率。 它可以把經常使用的資料存放在記憶體中,就不用每次都得到檔案或資料庫提取。 當然我們也可以自行實作這樣子的機制,只是 ASP.NET 都幫我們做好了,讓我們不用寫程式碼就可以處理複雜的快取。 ASP.NET 提供二種不同的快取:

  • 應用程式快取 (Application caching)
    應用程式快取是透過程式碼將資料以 key/value 的型態儲存在記憶體中。 它有點類似網站之中的 Application State ,不同的是,它的生命週期不像 Application 會跟隨整個網站的生命週期。 它會隨著記憶體空間的限制或時間過期等因素,自動的由集合中被移除。
  • 網頁輸出快取 (Page output caching)
    網頁輸出快取可以將 render 後的網頁的 html 儲存起來,提供給後續相同的網頁要求,以減少回應時間。

部署網站

Websites, by default, are entirely file based. This means that the source code is usually deployed to the server. The server then compiles that code when pages are requested. In this scenario, you can deploy a website to a web server by simply copying the files to the correct directory on the server. No special deployment software is required.

If your website is to be deployed to an array of web servers, you can use any file-synchronization tool to copy the files between the servers. This allows you to deploy to a master server and have the deployment synchronized across the web farm.

If your website has a database, requires special web server configuration, or needs different configuration settings in a release environment, simply copying files will be insufficient.

Visual Studio 2010 includes a new Publish Web dialog box that allows you to configure each of these settings once, and then publish a website to one or more web servers with a single click.

2012年10月8日 星期一

全球化與當地語系的設定

About ASP.NET Resources

To display an ASP.NET page in one of several different languages, you could prompt the user for his or her preferred language, and then write if-then statements to update the text of your page. However, that would be a complex and time-consuming.

ASP.NET uses resource files to support multiple languages. A resource file contains a language-specific set of text for a page or the entire site. Your code accesses a resource file based on the user's requested language.

If a resource file exists for that language, ASP.NET uses it and shows your site in the requested language. If no resource file exists for the given request, ASP.NET uses the default language setting for the site.

資料檔的類型有兩種:區域和全域。

設定協助工具

網站的協助工具 (Accessibility, VisualStudio 中翻成「網頁可及性」) 指的就是無障礙網頁的設計。 它的目的是協助使用非傳統I/O介面的使用者,也可以很方便地使用網站。 例如:有些使用者使用特殊的滑鼠,或者使用螢幕助讀器 (screen readers) 存取網站內容,而不是傳統的螢幕。

驗證使用者

ASP.NET 支援至少四種認證:

  • Windows authentication
  • Forms authentication
  • Passport authentication
  • Anonymous access

Membership

User Profile

ASP.NET 會員管理機制

Profile 指的是 ASP.NET 用來存取個人資料的一個類別,它是 ASP.NET 內建的一套管理機制,預設是必須搭配使用 SQL 的 aspnetdb 資料庫。 該資料庫系統中,同時含有 Membership 機制,可以實現會員管理功能。 也包含 roleManager 機制,可以做到群組化的會員管理機制。

WebPart

Theme

佈景主題 (Themes) 是用來設定控制項或頁面的樣式,讓整個網站看起來會有一致性的風格。 Theme 是樣式的集合,它主要由以下二部份組成:

  • 控制項面板 (.skin) :用來定義控制項的樣式屬性。
  • 樣式表 (.css) :用來定義樣式。

Master Page

Advantages of using master pages include the following:

  • allow you to centralize the common functionality of your pages.
  • allow you to create one controls and code and apply the results to a set of pages.
  • allow you to control over the layout of the final pages
  • allow you to customize the master pages from individual content pages.

2012年10月1日 星期一

使用ASP.NET內建物件

ASP.NET 提供了幾個系統物件,可以用來存取許多相當有用的資訊,例如取得使用者IP,瀏覽器種類等等。 這類物件必須透過 Page 物件的屬性取得,包含:

  • Request :這個物件包含目前 HTTP 要求的相關資訊。
  • Response :這個物件包含回應資訊,允許您將資訊,透過 HTTP 回應給用戶端。
  • Context :這個物件提供網頁執行內容的相關資訊。
  • Browser :取得或設定關於用戶端瀏覽器的資訊。
  • Server :這個屬性提供常用的 HtmlEncodeMapPath 方法。
  • Application :取得目前 Web 要求的 HttpApplicationState 物件。
  • Session :這個屬性提供目前要求的工作階段(Session)資訊。
  • Trace :追蹤並顯示關於 Web 要求的執行詳細資料。

自訂網站錯誤處理

Custom Web Server Controls

User Controls

在 Web 應用程式中,要建立自訂控制項有二種方法:

  • User Control:將數個Web控制項組合成單一的控制項。
  • Custom Web Server Control :繼承現有Web控制項並加以擴充功能成新的控制項。

下圖是 VS2008 裡的項目名稱

在 VS2010 裡的項目名稱則略有不同

若是在 Windows 應用程式中,你可以新增以下二種項目來建立自訂的控制項。

  • User Control:這個項目會直接繼承 UserControl 類別,可用來將數個 Windows Form 控制項組合成單一的控制項。
  • Custom Web Server Control:這個項目會直接繼承 Control 類別,所以它只提供控制項的基本功能,其它功能如:圖形介面、事件程式碼等都要自行撰寫。

當然,若要自訂的控制項,功能與現有的 Windows Form 控制項類似的話,最簡單的方法就是直接繼承 Windows Form 控制項。 這樣做可以保留 Windows Form 控制項的所有繼承功能,然後藉由加入自訂屬性、方法或其他功能來擴充該功能。

網站巡覽控制項

伺服器端狀態管理

驗證控制項

用戶端狀態管理