自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

使用自定義類替換Sys.Services.ProfileService對象

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

需要注意的就是順序,我們一般會使用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é)點加上了LoadProperties屬性,表明需要預加載Profile中的ZipCode和Address這個 Profile Group下的City屬性。另外,我們將EnablePartialRendering屬性設為了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中默認的ProfileService,而緊接著就是對于ProfileService的使用:設定其Path以及預加載的 Properties。在引入之后千萬不能忘了要將這些信息進行保留。但是這兩者之間無法插入任何代碼,因此我們可以在 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

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

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

【編輯推薦】

  1. ASP.NET中的WebRequestExecutor
  2. IIS6的ASP.NET ISAPI請求處理過程
  3. ASP.NET中的備份
  4. 淺談ASP.NET ISAPI
  5. ASP.NET的IIS ISAPI extension
責任編輯:佚名 來源: IT168
相關推薦

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-02-20 09:19:56

AJAXASP.NETWeb Service

2009-07-23 16:44:51

AdRotator控件ASP.NET

2009-01-16 13:17:16

AjaxASP.NET.NET

2009-01-04 13:27:10

URL RewriteIISASP.NET

2009-07-27 09:29:38

ASP.NET中Jav

2009-07-30 13:33:55

ASP.NET中的co

2009-07-29 15:51:29

ASP.NET中執(zhí)行w

2009-07-24 10:10:22

ASP.NET

2009-07-24 16:17:42

WebRequestEASP.NET

2011-06-08 11:05:38

getpost

2009-07-20 16:04:37

ASP.NET fra

2009-07-22 09:11:02

Action方法ASP.NET MVC

2009-12-25 10:36:10

ASP.NET 和 X

2009-03-13 09:48:33

ASP.NETAjaxJQuery

2009-07-23 14:47:03

Page_Load方法ASP.NET

2009-05-31 08:54:22

WEB開發(fā)ASP.NETApplication
點贊
收藏

51CTO技術棧公眾號