ConfigSectionSample.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Web.Configuration;
  3. public class ConfigSectionSample
  4. {
  5. public static void GetAuthServiceSection()
  6. {
  7. // Get the Web application configuration.
  8. System.Configuration.Configuration configuration =
  9. WebConfigurationManager.OpenWebConfiguration("/aspnetTest");
  10. // Get the external Web services section.
  11. ScriptingWebServicesSectionGroup webServicesSection =
  12. (ScriptingWebServicesSectionGroup)configuration.GetSectionGroup(
  13. "system.web.extensions/scripting/webServices");
  14. // Get the authentication service section.
  15. ScriptingAuthenticationServiceSection authenticationSection =
  16. webServicesSection.AuthenticationService;
  17. }
  18. public static void GetProfileServiceSection()
  19. {
  20. // Get the Web application configuration.
  21. System.Configuration.Configuration configuration =
  22. WebConfigurationManager.OpenWebConfiguration("/aspnetTest");
  23. // Get the external Web services section.
  24. ScriptingWebServicesSectionGroup webServicesSection =
  25. (ScriptingWebServicesSectionGroup)configuration.GetSectionGroup(
  26. "system.web.extensions/scripting/webServices");
  27. // Get the profile service section.
  28. ScriptingProfileServiceSection profileSection =
  29. webServicesSection.ProfileService;
  30. }
  31. public static void GetConverterElement()
  32. {
  33. // Get the Web application configuration.
  34. System.Configuration.Configuration configuration =
  35. WebConfigurationManager.OpenWebConfiguration("/aspnetTest");
  36. // Get the external JSON section.
  37. ScriptingJsonSerializationSection jsonSection =
  38. (ScriptingJsonSerializationSection)configuration.GetSection(
  39. "system.web.extensions/scripting/webServices/jsonSerialization");
  40. //Get the converters collection.
  41. ConvertersCollection converters =
  42. jsonSection.Converters;
  43. if ((converters != null) && converters.Count > 0)
  44. {
  45. // Get the first registered converter.
  46. Converter converterElement = converters[0];
  47. }
  48. }
  49. }