http://support.microsoft.com/kb/910442,這是中文的,機器翻譯的,不太容易看懂,英文的是:http://support.microsoft.com/kb/910442/en-us。
記錄幾個要點:
Web Resource是什麼?解決什麼問題?Web
Resource使用一種稱為WebResouce.axd的處理程式(Hanlder),該處理程式用來從Assembly中檢索抽取(retrieve)靜态資源檔案并傳回給浏覽器。處理程式WebResource.axd的類型是AssemblyResourceLoader。
Web Resource是怎樣解決這些問題的(Web Resource是如何工作的How Web Resource Work)?也就是Web
Resource是怎樣根據請求從Assembly中檢索抽取靜态檔案并傳回給用戶端的(分解開來,這裡有兩個個問題(1)針對WebResouce.axd的請求時如何産生的;(2)處理程式WebResource.axd處理該請求的具體過程是怎樣的)?針對前面的問題(2)(問題(1)的答案見下面的第4點),回答如下:When
a request comes in from the client for WebResource.axd, the handler looks for
the Web Resource identifier in
theQueryString method of
the Request object(當一個針對WebResource.axd的請求從用戶端進來時,WebResource.axd處理程式從該請求的QueryString方法中查找Web
Resource identifier). Based on the value of the Web Resource identifier, the
handler then tries to load the assembly that contains this
resource(然後,WebResource.axd試圖加載包含Web Resource identifier所指資源的Assembly). If
this operation is successful, the handler will then look for the assembly
attribute and load the resource stream from the assembly. Finally, the handler
will grab the data from the resource stream and send it to the client together
with the content type that you specify in the assembly attribute。The URL
for WebResource.axd looks like the following:
The format of this URL is
WebResource.axd?d=encrypted
identifier&t=time stamp value. The "d"
stands for the requested Web Resource. The "t" is the timestamp for the
requested assembly, which can help in determining if there have been any
changes to the resource.
如何将靜态資源檔案嵌入Assembly?
如何從Assembly中取出靜态資源檔案(即如何生成對處理程式WebResource.axd的請求)?For getting the
Web Resource, I have used
the GetWebResourceUrl method, which is
a method of the ClientScriptManagerclass
that is typically used for managing client-side scripts. This method returns a
URL reference to the server-side resource that is embedded in an assembly.
The GetWebResourceUrl method accepts
the following two parameters:
Type: The type of the server-side resource
Resource Name: The name of the server-side resource
To use this method, first you have to create an instance of
the ClientScriptManager class and get
the type of the class as shown below.When you have an instance of
this class, you then have to call this method and pass the appropriate
parameters as shown below, where I create
a HyperLink button, and set
the NavigateURL method to point to an
embedded HTML resource.
回到上面1的問題,Web
Resouce解決什麼問題?解決的是為用戶端傳回資源檔案的問題,是以如果你知道了資源檔案的位置(也就是說如果你請求的資源檔案不再Assembly中),完全沒有必要使用Web
Resource。