Saturday 22 October 2011

Web config file in ASP .net

Description of web config file :
Web.config file  is a configuration file for the Asp .net web application. An Asp .net application has one or more web.config file which keeps the configurations required for the corresponding application. 
Web.config file is written in XML with specific tags having specific meanings.
Some point in Web Config File:
A web Application can contain more than one web config file .and it reside  different sub-directories of your web application. Web config file in sub-directory take precedence over the setting that are specified in the  parent directory .
2. web config file protected by the IIS. so clients can not get to them. if u try to retrive an existing http:hellohome.com/webconfig then u will get Access denied or error .
3.When you modify the settings in the Web.Config file, you do not need to restart the Web service for the modifications to take effect.. By default, the Web.Config file applies to all the pages in the current directory and its subdirectories.
-----------------------------------------------------------------------------------------
The web config is XML file it can consist of any valid xml tags but the root element always be <configuration>

some tag description

1.The <configuration> tag has child tag, which we call section group, the <system.web> tag. A section group typically contains the setting sections, such as: compilation, customErrors, authentication, authorization, etc. The way this works is pretty straightforward: you simply include your settings in the appropriate setting sections. You want to use a different authentication mode for your Web application, you'd change that setting in the authentication section.

2.<authentication>

The authentication section controls the type of authentication used within your Web application, as contained in the attribute mode. You'll enter the value "None" if anyone may access your application. If authentication is required, you'll use "Windows", "Forms" or "Passport" to define the type of authentication. For example:

<authentication mode="Windows" />

3.<authorization>

To allow or deny access to your web application to certain users or roles, use <allow> or <deny> child tags.

<authorization>
<allow roles="Administrators,Users" />
<deny users="*" />
</authorization>

It's important to understand that ASP.NET's authorization module iterates through the sections, applying the first rule that corresponds to the current user. In this example, users carrying the role Administrators or Users will be allowed access, while all others (indicated by the * wildcard) will encounter the second rule and will subsequently be denied access.

4.<compilation>

Here, you can configure the compiler settings for ASP.NET. You can use loads of attributes here, of which the most common are debug and defaultLanguage. Set debug to "true" only if you want the browser to display debugging information. Since turning on this option reduces performance, you'd normally want to set it to "false". The defaultLanguage attribute tells ASP.NET which language compiler to use, since you could use either Visual Basic .NET or C# for instance. It has value vb by default.

5.<customErrors>

To provide your end users with custom, user-friendly error messages, you can set the mode attribute of this section to On. If you set it to RemoteOnly, custom errors will be shown only to remote clients, while local host users will see the ugly but useful ASP.NET errors -- clearly, this is helpful when debugging. Setting the mode attribute to Off will show ASP.NET errors to all users.

If you supply a relative (for instance, /error404.html) or absolute address (http://yourdomain.com/error404.html) in the defaultRedirect attribute, the application will be automatically redirected to this address in case of an error. Note that the relative address is relative to the location of the Web.config file, not the page in which the error takes place. In addition you can use <error> tags to provide a statusCode and a redirect attribute:

<customErrors mode="RemoteOnly" defaultRedirect="/error.html">
<error statusCode="403" redirect="/accessdenied.html" />
<error statusCode="404" redirect="/pagenotfound.html" />
</customErrors>

No comments:

Post a Comment