国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

在ASP.NET 2.0中建立站點(diǎn)導(dǎo)航層次(4)

2024-07-10 13:12:43
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  顯式表達(dá)式使開(kāi)發(fā)者對(duì)包含本地資源的文件和資源鍵(resource key)的名稱(chēng)有更強(qiáng)的控制能力。在示例web.sitemap中,第一個(gè)元素使用了顯式資源表達(dá)式。顯式表達(dá)式在每個(gè)屬性上指定。第一個(gè)元素的title屬性使用了顯式表達(dá)式。顯式表達(dá)式必須以$resource:開(kāi)頭。在這個(gè)標(biāo)識(shí)符之后,開(kāi)發(fā)者必須提供資源文件的根名稱(chēng)和資源鍵。開(kāi)發(fā)者可以選擇提供一個(gè)默認(rèn)值。在例子中,表達(dá)式$resources: title, mytitle , home表明提供程序應(yīng)該查看以"title"開(kāi)頭的資源文件。對(duì)于發(fā)送法語(yǔ)頭信息的瀏覽器開(kāi)說(shuō),提供程序會(huì)查找title.fr.resx資源文件。接下來(lái)提供程序查看鍵為mytitle的資源。如果提供程序無(wú)法找到這種資源,它會(huì)把字符串"home"作為默認(rèn)值。

  你可以運(yùn)行示例來(lái)查看站點(diǎn)地圖本地化的效果。把英語(yǔ)作為默認(rèn)語(yǔ)言的瀏覽器會(huì)顯式英語(yǔ)文本。如果使用ie,你可以通過(guò)點(diǎn)擊"工具->internet選項(xiàng)",并在"通用"選項(xiàng)卡點(diǎn)擊"語(yǔ)言"按鈕,點(diǎn)擊"添加"按鈕并選擇添加"法語(yǔ)"。如果需要,還需要選中法語(yǔ)并點(diǎn)擊"向上移動(dòng)"按鈕,使它成為ie的默認(rèn)請(qǐng)求語(yǔ)言。把默認(rèn)的語(yǔ)言改成法語(yǔ)之后,刷新示例頁(yè)面。請(qǐng)注意,menu、treeview和sitemappath控件中的文本自動(dòng)地顯式為app_globalresources目錄中存放的法語(yǔ)資源文件中的法語(yǔ)文本。

  web.sitemap的內(nèi)容

  以下是引用片段:
<?xml version="1.0" encoding="utf-8" ?>  
<sitemap xmlns="http://schemas.microsoft.com/aspnet/sitemap-file-1.0" enablelocalization="true">  
<sitemapnode url="~/default.aspx" title=" $resources: title, mytitle , home" description="default page description when no localized value exists." >  
<sitemapnode url="~/category.aspx" resourcekey="category">  
<sitemapnode title="autos" description="autos" url="~/autos.aspx" resourcekey="autos" />  
<sitemapnode title="games" description="games" url="~/games.aspx" resourcekey="games" />  
<sitemapnode title="health" description="health" url="~/health.aspx" resourcekey="health" />  
<sitemapnode title="news" description="news" url="~/news.aspx" resourcekey="news" />  
</sitemapnode>  
</sitemapnode>  
</sitemap>  

  修改提供程序(provider)返回的站點(diǎn)導(dǎo)航數(shù)據(jù)

  存儲(chǔ)在web.sitemap中、供xmlsitemapprovider使用的導(dǎo)航數(shù)據(jù)是靜態(tài)的--這些數(shù)據(jù)被載入內(nèi)存中并作為只讀數(shù)據(jù)存儲(chǔ)。但是,很多站點(diǎn)的導(dǎo)航結(jié)構(gòu)是根據(jù)查詢(xún)字符串的值來(lái)參數(shù)化的。例如,新聞組(newsgroup)站點(diǎn)可能擁有良好定義的頁(yè)面結(jié)構(gòu)(例如,主頁(yè)、新聞?lì)悇e頁(yè)面和新聞內(nèi)容頁(yè)面),但是實(shí)際的內(nèi)容可能會(huì)有很大的不同,這依賴(lài)于查詢(xún)字符串中的標(biāo)識(shí)符。盡管把每種可能的查詢(xún)字符串值都存儲(chǔ)在元素中也是可能的,但是即使是中等數(shù)量的查詢(xún)字符串值,也要求sitemap文件包含數(shù)百個(gè)元素。

  站點(diǎn)導(dǎo)航特性在sitemapprovider基類(lèi)中暴露了sitemapresolve事件。可以使用sitemap.sitemapresolve或直接使用提供程序sitemap.provider.sitemapresolve來(lái)執(zhí)行這個(gè)事件。這個(gè)事件的返回值是一個(gè)sitemapnode實(shí)例。你可以在自己的事件處理程序中編寫(xiě)自定義邏輯來(lái)建立sitemapnode實(shí)例的層次結(jié)構(gòu)。這個(gè)邏輯可以修改每個(gè)sitemapnode的屬性,因此url和title等屬性會(huì)反映查詢(xún)字符串帶有的數(shù)據(jù)信息。

  下面的例子在global.asax中注冊(cè)了一個(gè)事件處理程序。這個(gè)事件處理程序的代碼是app_code目錄中的一個(gè)類(lèi)。這個(gè)自定義的類(lèi)復(fù)制與當(dāng)前頁(yè)面對(duì)應(yīng)的sitemapnode實(shí)例。xmlsitemapprovider返回的節(jié)點(diǎn)都是只讀的,而調(diào)用sitemapnode上的clone方法返回的是可寫(xiě)入的節(jié)點(diǎn)。在實(shí)例中,如果給clone傳遞了true值,將導(dǎo)致當(dāng)前的sitemapnode和它的所有父節(jié)點(diǎn)都是可寫(xiě)入的。這個(gè)類(lèi)的代碼的其它部分檢查當(dāng)前的頁(yè)面和當(dāng)前頁(yè)面的查詢(xún)字符串,確定當(dāng)前頁(yè)面位于站點(diǎn)層次結(jié)構(gòu)的什么位置。代碼修改了url和title屬性,包含一些額外的信息,這樣sitemappath控件顯示的導(dǎo)航ui就反映了網(wǎng)站用戶(hù)為到達(dá)當(dāng)前頁(yè)面的實(shí)際點(diǎn)擊路徑。

  運(yùn)行示例的時(shí)候,你開(kāi)始位于站點(diǎn)的主頁(yè)。sitemappath控件也反映了這一點(diǎn)。點(diǎn)擊任何鏈接都會(huì)帶你進(jìn)入分類(lèi)頁(yè)面,它顯示相關(guān)新聞?lì)悇e中的新聞鏈接。請(qǐng)注意,如果你把鼠標(biāo)停留在sitemappath控件的最后一個(gè)鏈接上,瀏覽器狀態(tài)欄中顯示的url包含了查詢(xún)字符串信息(它指定了新聞?lì)悇e)。點(diǎn)擊任何一個(gè)發(fā)布鏈接都會(huì)把你帶回到新聞發(fā)布頁(yè)面。如果你把鼠標(biāo)停留sitemappath控件的鏈接上,可以注意到控件中的最后兩個(gè)鏈接帶有的url和title包含了點(diǎn)擊路徑的正確查詢(xún)字符串和描述信息。如果你導(dǎo)航到站點(diǎn)的主頁(yè),并點(diǎn)擊其它的新聞組和內(nèi)容鏈接,sitemappath控件會(huì)被更新并反映第二次點(diǎn)擊的鏈接。

  以下是引用片段:

public class pathexpansionhandler 
public shared function expandpath(byval sender as object, byval e as sitemapresolveeventargs) as sitemapnode 

  '獲取當(dāng)前和之前節(jié)點(diǎn)的引用 
dim nodecopy as sitemapnode = sitemap.currentnode.clone(true)  
dim tempnode as sitemapnode = nodecopy  

'check if there is a newsgroup type in the query string 
dim typeid as string = nothing  
dim typeidurlencoded as string = nothing  
if not string.isnullorempty(e.context.request.querystring("type")) then 
typeid = e.context.server.htmlencode(e.context.request.querystring("type")) 
typeidurlencoded = e.context.server.urlencode(e.context.request.querystring("type")) 
end if 

  '首先執(zhí)行發(fā)布頁(yè)面url的固定 
  '如果查詢(xún)字符串中包含發(fā)布id,我們就知道當(dāng)前節(jié)點(diǎn)式發(fā)布頁(yè)面 
if not string.isnullorempty(e.context.request.querystring("postingid")) then 
dim postingid as string = _ 
e.context.server.htmlencode(e.context.request.querystring("postingid")) 
dim postingidurlencoded as string = _ 
e.context.server.urlencode(e.context.request.querystring("postingid")) 
dim newurl as string = tempnode.url + "?type=" + typeidurlencoded + "&postingid=" + postingidurlencoded  
dim newtitle as string = tempnode.title + ": " + postingid  
tempnode.url = newurl 
tempnode.title = newtitle 

tempnode = tempnode.parentnode 
end if 

  '然后,對(duì)新聞組頁(yè)面進(jìn)行固定 
  '這時(shí)候nodecopy 變量知賢了新聞組節(jié)點(diǎn) 
if not string.isnullorempty(e.context.request.querystring("type")) then 
dim newurl as string = tempnode.url + "?type=" + typeidurlencoded  
dim newtitle as string = tempnode.title + ": " + typeid  
tempnode.url = newurl 
tempnode.title = newtitle 
end if 

  '最后返回當(dāng)前節(jié)點(diǎn) 
return nodecopy 
end function 
end class 



收集最實(shí)用的網(wǎng)頁(yè)特效代碼!

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 彩票| 满城县| 扶余县| 彭州市| 礼泉县| 凤翔县| 饶阳县| 六盘水市| 股票| 元朗区| 桦川县| 德令哈市| 宜兴市| 望奎县| 大城县| 临武县| 浮山县| 依安县| 南城县| 遂宁市| 莱州市| 阿拉善左旗| 永寿县| 惠安县| 米易县| 迭部县| 孟村| 上蔡县| 墨玉县| 定日县| 元谋县| 岳池县| 田阳县| 阳春市| 夹江县| 双柏县| 会泽县| 海丰县| 兰州市| 贵德县| 浏阳市|