web config Configuration File

web config Configuration File – सभी Web Applications Machine.config व Root पर स्थित Web.config File से विभिन्न Settings की Information को Inherit करते हैं। साथ ही हम हमारी जरूरत के अनुसार प्रत्येक Web Application के साथ Additional Web Settings भी Add कर सकते हैं।

उदाहरण के लिए हम Authentication हेतु कोई Specific Method Use कर सकते हैं, या किसी Specific तरीका का Debugging Set कर सकते हैं, या कोई Default Language Set कर सकते हैं या Custom Error Page Set कर सकते हैं। आदि, आदि। और ये सबकुछ करने के लिए हमें हमारे Web Application के Root Folder में Web.config File को Setup करना होता है।

यहां समझने वाली एक महत्वपूर्ण बात ये है कि Web.config File में Specified Settings, Machine.config File में Specified सभी Settings को Override नहीं कर सकता। कुछ Settings जैसे कि Process Model Settings को Per-Application Basis पर Change नहीं किया जा सकता। जबकि अन्‍य Settings Application-Specific होती हैं, जो कि Web.config File के माध्‍यम से Change हो सकती हैं।

हालांकि हमारे Project की किसी Sub-Directory में स्थित Web.config द्वारा इन Settings को Change नहीं किया जा सकता। इसीलिए Application Specific Web.config File का Root Directory में होना जरूरी होता है।

किसी ASP.NET Configuration File का सारा Content <configuration> Element के बीच Enclosed होता है। इस Element में<system.web>नाम का एक Child Element होता है, जिसे ASP.NET Settings के लिए Use किया जाता है।

<system.web> Element के साथ ही<appSettings> Element भी एक Separate Element होता है, जिसका प्रयोग Custom Settings को Specify करने  तथा <connectionStrings> Element के माध्‍यम से Underlying Database के साथ Connectivity स्थापित करने हेतु Connection String को Specify करने के लिए Specify किया जा सकता है, जिस पर ASP.NET के अन्‍य Features भी निर्भर करते हैं।

एक Simple Web.config File अपनी Simplest Configuration Information के साथ कुछ निम्नानुसार Specified होता है, जिसे Visual Studio स्वयं हमारे Web Application के लिए Default रूप से Generate करता है:

File Name:Web.config
<?xmlversion="1.0"?>

<configuration>
<system.web>
<compilationdebug="true"targetFramework="4.5" />
<httpRuntimetargetFramework="4.5" />
</system.web>
</configuration>

किसी भी अन्‍य XML Document की तरहही Web.config File भी एक Case-Sensitive File होती है। इस File में Specified प्रत्येक Setting को Camel Case में Specify किया जाता है, जिसकी शुरूआत Lowercase Letter से होती है। यानी हम<system.web> Element को <System.Web> Specify नहीं कर सकते।

इस Configuration File का<system.web> Section ASP.NET Configuration का सबसे महत्वपूर्ण Section होता है। इसी के बीच विभिन्न ASP.NET Features से सम्बंधित Settings को Enclose किया जाता है।

इसके अलावा ज्यादातर ASP.NET Applications की Configuration File में<appSettings> Section को भी Specify किया जाता है, जिसके अन्तर्गत Current Application से सम्बंधित Application -Specific Configuration Settings को Specify किया जाता है।

साथ ही Database आधारित Applications में<connectionStrings> Section भी Specify किया जाता है और इस Section के माध्‍यम से Application व Underlying Database के बीच Connection Set करने से सम्बंधित Settings को Specify किया जाता है।

इसी तरह से<system.webServer> Section Specify करके हम ASP.NET Pipeline को Additional HTTP Handlers व HTTP Modules का प्रयोग करते हुए Extend कर सकते हैं। इस प्रकार से यदि हम एक Basic Structure देखें, तो Web.config File के विभिन्न Basic Elements का Basic Structure निम्नानुसार हो सकता है:

File Name:Web.config
<?xmlversion="1.0"?>
<configuration>
<appSettings />
<connectionStrings />
<system.web>
<!-- ASP.NET configuration sections go here. -->
</system.web>
<system.webServer />
</configuration>

Configuration Inheritance

ASP.NET एक Multilayered Configuration System Use करता है जो हमें हमारे Application के Different Part के लिए Different Settings को Specify करने की सुविधा देता है। इस तकनीक का उपयोग करने के लिए हमें हमारे Web Application की Virtual Directory में Additional Sub-Directories Create करने की जरूरत पडती है। इन Sub-Directories में Separate web.config Files हो सकती हैं, जिनमें Additional Settings को Specify किया जा सकता है।

चूंकि ASP.NET Configuration Inheritance को Support करता है, इसलिए प्रत्येक Sub-Directory में Create की गई web.config File अपने Parent Directory में Specify की गई web.config File की Settings को Inherit कर लेता है।

उदाहरण के लिए मानलो कि हम http://localhost/Dir/SubDir/SubSubDir/MyPage.aspx Page की Request करते हैं। इस स्थिति में निम्नानुसार कई Levels की Settings अपना Role Place करती हैं:

  • सबसे पहले config File में Specified Settings Apply होती हैं।
  • फिर Web Application के Root Folder में Exist config File में Specified Settings Apply होती हैं। ये Web.config File उसी Directory में Exist होती है, जिसमें Machine.config File Exist होती है।
  • अब यदि इस Request URL के Dir Folder में config File Exist हो, तो उस Web.config File की Settings Apply होती हैं।
  • इसके बाद अब यदि इस Request URL के SubDir Folder मेंconfig File Exist हो, तो उस Web.config File की Settings Apply होती हैं।
  • इसके बाद अन्त में यदि इस Request URL के SubSubDir Folder मेंconfig File Exist हो, तो उस Web.config File की Settings Apply होती हैं और ये प्रक्रिया आगे भी जारी रहती है।

इस Sequence में इस बात का ध्‍यान रखना जरूरी होता है कि हालांकि हम जितनी चाहें, उतनी Level की Sub-Directories में Web.config File Create करते हुए Individual Settings को Apply कर सकते हैं, लेकिन अलग-अलग Level पर भी हमें इस बात का ध्‍यान रखना होता है कि कुछ Settings को केवल Machine.config द्वारा ही Apply किया जा सकता है व कुछ Settings को केवल Individual Application के Root Level की Web.config File द्वारा।

उदाहरण के लिए Web Application के Authentication को केवल Application के Root Level की Web.config File में Specified Settings द्वारा ही Apply किया जा सकता है, ताकि केवल Authenticated Users ही हमारे Web Application को Access कर सकें।

इस पूरी प्रक्रिया को हम निम्न चित्र द्वारा बेहतर तरीके से Represent कर सकते हैं:

web config Configuration File - Hindi

ASP.NET  की Web.config File द्वारा Current Web Application पर Settings को Apply करने के इस तरीके के कारण Sub-Directories की Web.config File में काफी कम Settings को Specify किया जा सकता है, जो कि हमारे Web Application की अन्‍य Directories से भिन्न हो।

Multiple Directories में अलग-अलग Web.config File में Different Settings को Specify करने का एक मुख्‍य कारण Different Sub-Directories पर Different Security Settings को Apply करना होता है।

यानी जिन Files को हमें Secured रखना होता है, उन्हें एक अलग Sub-Folder में Place करके उस Sub-Folder में एक Separate Web.config File को Create किया जाता है। ASP.NET की Web.config File को हम Apache Web Server की .htaccess File के समान मान सकते हैं।

यदि Multiple Directories के बीच Multiple Web.config File के कारण Settings Conflict होता है, तो Sub-Directory की Web.config File की Settings हमेंशा Parent Directory की Web.config File में Specified Settings से Override होता है। हालांकि यदि हम चाहें तो इस Web.config File में Locked Sections Create कर सकते हैं, जो कि Parent Web.config File  की Inherited Settings से प्रभावित नहीं होता।

जब हम Visual Studio का प्रयोग करते हुए Project-less Website नहीं बल्कि एक Web Project Create करते हैं, तब हमारे Project में Web.Debug.config व Web.Release.config नाम की दो और Configuration Files Create होती हैं। इन दोनों Files का प्रयोग करके हम हमारे Web Application की Settings में Testing व Deployment के दौरान Use की जाने वाली Settings को Specify कर सकते हैं।

हालांकि जब हम हमारा Web Application Visual Studio के Environment में Run करते हैं, तब इन दोनों Files का कोई उपयोग नहीं होता। बल्कि Visual Studio इन दोनों Files को Ignore कर देता है। इन दोनों Files का उपयोग केवल तब होता है, जब हम हमारे Web Application का Deployment Package Build करते हैं।

Buy this eBook to read more about …

  • <location> Element
  • <system.web> Element
  • <system.webServer> Element
  • <appSettings> Element
  • <connectionStrings> Element
  • Accessing/Manipulating Configuration Sections Programmatically
ASP.NET Configuration
Extending ASP.NET Config File Structure

Core ASP.NET WebForms in Hindi - BccFalna.com: TechTalks in Hindiये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Core ASP.NET WebForms with C# in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी। 

Core ASP.NET WebForms in Hindi | Page:647 | Format: PDF

BUY NOW GET DEMO REVIEWS