Obtain the parameters set in Web. config in Asp. Net! (Front and back-end code example), asp. netweb. config

Source: Internet
Author: User
Tags connectionstrings

Obtain the parameters set in Web. config in Asp. Net! (Front and back-end code example), asp. netweb. config

1. Set code in Web. config

<Deleetask>
<Add key = "deleted" value = "1"/> <! -- Delete a flag -->
</AppSettings>

2. Create sys. cs in App_Code

// Note: You need to add a reference namespace using.

Public class sys
{
Public static int deleted = int. Parse (ConfigurationManager. deleettings ["deleted"]);
}

Iii. calls in cs files

If (aaa = systemparam. deleted)

{

.......

}


ASPNET obtains the webconfig data connection Field

Page type:
String constr = ConfigurationManager. ConnectionStrings ["connString"]. ConnectionString
Web. config:
<ConnectionStrings>
<Add name = "connString" connectionString = "server = database address; database = database; user id = database login user; password = database login password;" providerName = "System. data. sqlClient "/>
</ConnectionStrings>

How can I call the SQL database connection configured in the webconfig of ASPNET?

First, add using System. Configration.
Use ConfigrationManager. ConnectinStrings [""]. ConnectionString. Brackets are the name in the configuration file.

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.