Teach Yourself Visual Studio® .NET 2003 in 21 Days [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Teach Yourself Visual Studio® .NET 2003 in 21 Days [Electronic resources] - نسخه متنی

Jason Beres

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید









Understanding the Web.Config File


The Web.Config file is an XML-based configuration file that's used by ASP.NET to set options for your application. Each new project you create has its own Web.Config file. Within a project, you can have multiple Web.Config files in different folders, setting up a hierarchy of what settings to use for each folder.

When you're just getting your feet wet with ASP.NET, you'll normally just use the one default Web.Config file on a per-project basis.

As you've seen in the previous section, you can use the Web.Config file to set application-level settings for state management. You can also set security on directories, set up page-and session-level debugging, and store your own custom configuration information.

The biggest benefit to the Web.Config file is that you have a place to store variable data that might have otherwise been kept in application-level or session-level variables in ASP. For example, database connection information, folder locations, and virtual path information can all be stored in the Web.Config file. With an ASPX page, you can retrieve information from the Web.Config file by using the ConfigurationSettings class.

To see how this works, take a look at the custom AppSettings section in the following Web.Config file:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="cn" value="Server=Enterprise;UID=NCC1701D;
Pwd=CaptJaneway;Database=Ships"/>
<add key="pics" value="C:\InetPub\storage\"/>
<add key="picsHTTP" value="http://www.picsserver.com/public/"/>
</appSettings>
<system.web>

Each of the values stored can be accessed by retrieving the correct key attribute in code. To do this, you would use the following code:


sqlCn = ConfigurationSettings.AppSettings("cn")

You could also use the GetSettings method to return an array of the items in the AppSettings collection. Storing variable data in the Web.Config file is important for two reasons:


  • You don't need to recompile your application if a setting changes; you simply modify the Web.Config file.


  • You aren't consuming memory using session- or application-level variables.




/ 270