Use custom sections to expand the structure of the web. config and machine. config configuration files

Source: Internet
Author: User

Webconfig:

[Html]
<? Xml version = "1.0"?>
<! --
For more information about how to configure ASP. NET applications,
-->
<Configuration>
<ConfigSections>
<Section name = "RemotingObject" type = "RemotingObject"/>
</ConfigSections>
<System. web>
<Compilation debug = "true" targetFramework = "4.0"/>
</System. web>
<RemotingObject available = "true" pollTimeout = "00:01:00" location = "tcp: // OrderComputer: 8010/OrderService"/>
</Configuration>

Get custom node content:

[Csharp]
// Open the configuration file
Configuration config = WebConfigurationManager. OpenWebConfiguration ("~ /");
// Get the configuration section object
RemotingObject custSection =
(RemotingObject) config. GetSection ("RemotingObject ");
// Display configuration section information
LblInfo. Text + = "getting custom configuration section information... <br/>" +
"<B> Location: </B>" + custSection. Location +
"<Br/> <B> Available or not: </B>" + custSection. Available. ToString () +
"<Br/> <B> Timeout: </B>" + custSection. PollTimeout. ToString () + "<br/> ";

RemotingObject object class

[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Configuration;
 
/// <Summary>
/// Summary of RemotingObject
/// </Summary>
Public class RemotingObject: ConfigurationSection
{
// Define whether the remote object is available
[ConfigurationProperty ("available", IsRequired = false, DefaultValue = true)]
Public bool Available
{
Get {return (bool) base ["available"];}
Set {base ["available"] = value ;}
}
// Define the timeout time of the Remote Object
[ConfigurationProperty ("pollTimeout", IsRequired = true)]
Public TimeSpan PollTimeout
{
Get {return (TimeSpan) base ["pollTimeout"];}
Set {base ["pollTimeout"] = value ;}
}
// Define the location of the Remote Object
[ConfigurationProperty ("location", IsRequired = true)]
Public string Location
{
Get {return (string) base ["location"];}
Set {base ["location"] = value ;}
}
}

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.