[ASP.NET]ASP.NET 4.0 and Visual Studio 2010 Web Development Beta 1 Overview

ASP.NET 4.0 and Visual Studio 2010 Web Development Beta 1功能預覽

ASP.NET4.0+VS 2010的overview:http://www.asp.net/learn/whitepapers/aspnet40/

以下截取幾個看了比較有興趣的功能:

Auto-Start Web Applications

這個功能實在正點,還記得前一陣子我自己寫了一個偵測w3wp是否被回收的程式,因為ASP.NET有一點很讓人討厭,就是每次回收後,第一次啟動頁面都需要很久的時間,而我們看一下網頁中提到的,這不是很讓人驚艷嗎?

The auto-start feature provides a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP requests.

不過光是自動啟動又沒什麼了不起,下面這一段提到,自動啟動時還可以自己定義要做些什麼,例如載入預設的資訊又或者啟動某些服務:

For each application that is marked for auto-start, IIS7.5 sends a request to ASP.NET 4.0 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, ASP.NET instantiates the type defined by the preloadProvider attribute (as shown in the previous example) and calls into its public entry point.

After your initialization code runs in the Preload method and the method returns, the ASP.NET application is ready to process requests.

 

The Incredible Shrinking Session State

這一點一樣很正點,從以前的版本,ASP.NET的Session本來就有數種儲存模式,其中兩種是State Server跟SQL Server,將Session存到另一台主機或者資料庫中,這兩種模式,

優點是:可讓Session不受w3wp的影響,並減少AP Server的記憶體耗損。

缺點是:效能較慢一些,且所有程式物件需要可被序列化,序列化後的Size可能會變得很大,佔用更多的記憶體或disk空間。

針對這點,微軟終於也有solution了,透過config設定compressionEnabled來壓縮序列化物件的size。

 

Live Data Binding

ASP.NET4.0打算在AJAX功能上做些加強囉,透過{{ binding Name}}表示式來做client端物件的即時變動,十分的有趣,這個功能我真的覺得是繼LINQ之後又一個讓人搞迷糊的功能阿(LINQ很好用,希望這東西也一樣好用)...@@...

This type of binding is referred to as one-time binding because the expression is evaluated only once, at the time that the template is rendered. With one-way/one-time binding, if the source data changes after the template has been rendered (in the previous example, if the Name field changes), the rendered value will not be automatically updated.

You can use an alternative live-binding syntax in order to ensure that the target value is automatically updated whenever the source value changes. This is shown in the following example: 

<h3>{binding Name}</h3>

 

 

Refactoring the Microsoft AJAX Framework Libraries

對ASP.NET AJAX的基本libraries做了一些refactor的動作,除了新增兩個js做為template render跟ado.net的service之外,也改變了之前使用了ScriptManager時就會自動將整包的js下載到client端的現象,提供了三種設定模式:

Enabled — All Microsoft AJAX scripts are included (legacy behavior). This is the default value of the property.

Explicit — Each split script file must be added explicitly; it is up to you to make sure that you include all scripts that have dependencies on one another.

Disabled — All Microsoft ASP.NET AJAX script features are disabled and the ScriptManager control does not reference any scripts automatically.

設定的靈活性上有做了一些加強,refactor後目前ASP.NET4.0會有以下的js可供參考:

  • MicrosoftAjaxCore.js
  • MicrosoftAjaxComponentModel.js
  • MicrosoftAjaxSerialization.js
  • MicrosoftAjaxGlobalization.js
  • MicrosoftAjaxHistory.js
  • MicrosoftAjaxNetwork.js
  • MicrosoftAjaxWebServices.js
  • MicrosoftAjaxApplicationServices.js
  • MicrosoftAjaxTemplates.js (New for ASP.NET AJAX 4.0)
  • MicrosoftAjaxAdoNet.js (New for ASP.NET AJAX 4.0)

 

Routing in ASP.NET 4.0

這個特色乍看之下沒有什麼特別的,在ASP.NET3.5的SP1版本就有了,但ASP.NET4.0做了一些加強,Routing的意思我們可以用以下的例子作簡單的說明:

本來的網址:http://website/products.aspx?categoryid=12

設定Routing後的網址:http://website/products/software

其實概念就是URL的轉址而已,而這個轉址可以透過WebFormRouteHandler 這個類別在程式中動態指定,簡單的code如下:

01 public class Global : System.Web.HttpApplication  
02 {  
03 protected void Application_Start(object sender, EventArgs e)  
04 {  
05 RouteTable.Routes.Add("SearchRoute", new Route("search/{searchterm}",  
06 new WebFormRouteHandler("~/search.aspx")));  
07 RouteTable.Routes.Add("UserRoute", new Route("users/{username}",  
08 new WebFormRouteHandler("~/users.aspx")));  
09 }
  
10 }

 

算是一個蠻實用的功能吧。

 

New Field Templates for URLs and E-mail Addresses

哈哈,這個功能還挺方便的,以前要自己做還要費一點功夫,直接可從屬性中設定,挺好的:

ASP.NET 4.0 introduces two new built-in field templates, EmailAddress.ascx and Url.ascx. These templates are used for fields that are marked as EmailAddress or Url with the DataType attribute. For EmailAddress objects, the field is displayed as a hyperlink that is created by using the mailto: protocol. When users click the link, it opens the user's e-mail client and creates a skeleton message. Objects typed as Url are displayed as ordinary hyperlinks. 

1 [DataType(DataType.EmailAddress)]  
2 public object HomeEmail { get; set; }  
3 [DataType(DataType.Url)]  
4 public object Website { get; set; }

 

 

Visual Studio 2010 Web Designer Improvements

在開發工具上,VS 2010也打算要做一些改善囉,包含提供更多的snippets跟更強大的Jscript的intellisense,並讓CSS的設計工具更符合CSS2.1的國際標準,看起來確實很OK啦,不過身為開發人員,我還是希望VS能跑得更快一點,有時候光開一個web page就要等1-20秒鐘,有時還會當掉,真的很麻煩。

其他的東西無法一一細數,有興趣的人自己看上頭的網址吧,.net framework變動的真快速,3.5都還沒上手,4.0又接著要出來了,VS2008我還沒感受到它的好,VS2010又要出來了,持續改善是很好的,不過希望後續的新版本都能考量到版本間的兼容性,讓我們升版比較沒有壓力與負擔....

游舒帆 (gipi)

探索原力Co-founder,曾任TutorABC協理與鼎新電腦總監,並曾獲選兩屆微軟最有價值專家 ( MVP ),離開職場後創辦探索原力,致力於協助青少年培養面對未來的能力。認為教育與組織育才其實息息相關,都是在為未來儲備能量,2018年起成立為期一年的專題課程《職涯躍升的關鍵24堂課》,為培養台灣未來的領袖而努力。