偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

在ASP.NET中替換Sys.Services的方法

開(kāi)發(fā) 后端
本文介紹在ASP.NET中替換Sys.Services的方法,寫(xiě)一個(gè)類替換Sys.Services._ProfileService 類,甚至完全重寫(xiě)一個(gè)類,這個(gè)一般就看具體情況了。

使用自定義類替換Sys.Services.ProfileService對(duì)象

一般來(lái)說(shuō),這是最容易想到的辦法。我們可以寫(xiě)一個(gè)類替換Sys.Services._ProfileService 類(這個(gè)類完全通過(guò) prototype擴(kuò)展,因此對(duì)于繼承非常友好),甚至完全重寫(xiě)一個(gè)類,這個(gè)一般就看具體情況了。假設(shè)我們已經(jīng)定義了這么一個(gè)類 “Jeffz.Services.ProfileService”,并將其包含在MyProfile.Service.js中,就要開(kāi)始使用了。那么還要注意些什么呢?

需要注意的就是順序,我們一般會(huì)使用ScriptManager引入該JS,如下:

  1. <asp:ScriptManager ID="ScriptManager1" runat="server" 
    EnablePartialRendering="false"> 
  2. <Scripts> 
  3. <asp:ScriptReference Path="MyProfileService.js" /> 
  4. Scripts> 
  5. <ProfileService LoadProperties="ZipCode, Address.City" 
    Path="MyProfile.asmx"/> 
  6. asp:ScriptManager> 


我們?yōu)镻rofileService節(jié)點(diǎn)加上了LoadProperties屬性,表明需要預(yù)加載Profile中的ZipCode和Address這個(gè) Profile Group下的City屬性。另外,我們將EnablePartialRendering屬性設(shè)為了False,避免出現(xiàn)多余的代碼。

  1. <script src="/Value-Add-WebSite/WebResource.axd?d=...;t=..." type=
    "text/javascript"></script> 
  2. <script type="text/javascript"> 
  3. </script> 
  4. <script src="MyProfileService.js" type="text/javascript"></script> 

***行引入的是 MicrosoftAjax.js,它之中定義了ASP.NET AJAX中默認(rèn)的ProfileService,而緊接著就是對(duì)于ProfileService的使用:設(shè)定其Path以及預(yù)加載的 Properties。在引入之后千萬(wàn)不能忘了要將這些信息進(jìn)行保留。但是這兩者之間無(wú)法插入任何代碼,因此我們可以在 MyProfileService.js里添加如下的代碼,以保留這些信息:

  1. var path = Sys.Services.ProfileService.get_path();  
  2. if (!path)  
  3. {  
  4. path = Sys.Services._ProfileService.WebServicePath;  
  5. }  
  6. var properties = Sys.Services.ProfileService.properties;  
  7. var newnewInstance = new Jeffz.Services.ProfileService();  
  8. newInstance.set_path(path);  
  9. newInstance.properties = properties;  
  10. Sys.Services.ProfileService = newInstance

當(dāng)然,可能代碼會(huì)根據(jù)實(shí)際情況略有不同,但是注意JavaScript引入以及執(zhí)行的順序,在做任何自定義工作時(shí)都是非常重要的。

  有人也許會(huì)問(wèn),既然已經(jīng)重新定義了自己的實(shí)現(xiàn),為什么還要將其“偽裝”成默認(rèn)的ProfileService呢?因?yàn)檫@種“自定義”其實(shí)并不為“官方” 所承認(rèn),這么做能夠保證了兼容性,保證了第三方的組件也能使用Profile Service,即使它們沒(méi)有“意識(shí)”到?jīng)]有使用ASP.NET AJAX提供的默認(rèn)Profile Service。以上介紹在ASP.NET中替換Sys.Services的方法

【編輯推薦】

  1. ASP.NET中的WebRequestExecutor
  2. IIS6的ASP.NET ISAPI請(qǐng)求處理過(guò)程
  3. ASP.NET中的備份
  4. 淺談ASP.NET ISAPI
  5. ASP.NET的IIS ISAPI extension
責(zé)任編輯:佚名 來(lái)源: IT168
相關(guān)推薦

2009-07-24 16:05:05

調(diào)用Web ServiASP.NET

2009-07-21 10:24:21

.NET RIA SeASP.NET

2011-06-08 11:36:16

ASP.NETrender

2009-07-28 13:26:34

Render方法ASP.NET

2009-01-16 13:17:16

AjaxASP.NET.NET

2009-07-23 16:44:51

AdRotator控件ASP.NET

2009-02-20 09:19:56

AJAXASP.NETWeb Service

2009-07-29 15:51:29

ASP.NET中執(zhí)行w

2009-07-27 09:29:38

ASP.NET中Jav

2009-07-30 13:33:55

ASP.NET中的co

2009-01-04 13:27:10

URL RewriteIISASP.NET

2009-07-24 10:10:22

ASP.NET

2009-07-24 16:17:42

WebRequestEASP.NET

2009-07-20 16:04:37

ASP.NET fra

2009-07-22 09:11:02

Action方法ASP.NET MVC

2011-06-08 11:05:38

getpost

2009-03-13 09:48:33

ASP.NETAjaxJQuery

2009-12-25 10:36:10

ASP.NET 和 X

2009-05-31 08:54:22

WEB開(kāi)發(fā)ASP.NETApplication

2009-07-23 14:47:03

Page_Load方法ASP.NET
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)