How to replace Sys. Services in ASP. NET

Source: Internet
Author: User

Use a custom class to replace the Sys. Services. ProfileService object

In general, this is the easiest way to think. We can write a class to replace Sys. services. _ ProfileService class: this class is fully extended through prototype, so it is very friendly to inherit.) or even completely rewrite a class. This generally depends on the specific situation. Assume that we have defined such a class "Jeffz. Services. ProfileService" and included it in MyProfile. Service. js, we will start to use it. So what should we pay attention?

Note that the sequence is as follows:

 
 
  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> 


The LoadProperties attribute is added to the ProfileService node, indicating that the ZipCode in the Profile and the City attribute under the Profile Group must be preloaded. In addition, we set the EnablePartialRendering attribute to False to avoid unnecessary code.

 
 
  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> 

The first line introduces MicrosoftAjax. js, which defines the default ProfileService in ASP. net ajax, followed by the use of ProfileService: set its Path and preloaded Properties. After the introduction, you must never forget to retain the information. However, no code can be inserted between the two, so we can add the following code in MyProfileService. js to keep the information:

 
 
  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; 

Of course, the Code may be slightly different depending on the actual situation, but pay attention to the JavaScript introduction and execution sequence, it is very important to do any custom work.
Some people may ask, since we have redefined our own implementation, why should we "Disguise" it as the default ProfileService? This "Custom" is not recognized by the "official". This ensures compatibility and the use of Profile Service for third-party components, even if they do not "realize" that ASP is not used. net ajax provides the default Profile Service. The above describes how to replace Sys. Services in ASP. NET.

  1. WebRequestExecutor in ASP. NET
  2. IIS6 ASP. net isapi request processing process
  3. Backup in ASP. NET
  4. Introduction to ASP. NET ISAPI
  5. Iis isapi extension of ASP. NET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.