Friday 22 June 2012

2 ASP.NET Configurations



2  ASP.NET Configurations

·        2.1   How to Asp.Net configurations
·        2.2   How to Machine.Config
·        2.3   How to Web.Config
·        2.4   Elements in a web.config File
2.1  How to Asp.Net configurations
After an ASP.NET application is finished, it needs to be configured on an application Web Server for launching it as a Web site on the network system. The configuration information for the ASP.NET applications is stored XML based configuration files, so they are readable and can be edited in any XML editor or in Visual Studio .NET directly.
In ASP.NET, configuration information is stored in one of two files: machine.config or web.config. The main difference between these two files is that the machine.config file is applied system level configuration while the web.config is implemented to each application based on the inheritance rules.

2.2  How to Machine.Config
In ASP.NET, configuration information is stored in one of two files: machine.config or web.config. Machine.config file is using as root configuration file and provides ASP.NET configuration settings for every application in the Web server. Machine.config configuration file comes with the Microsoft .NET Framework and contains the default settings. While an application can have as many web.config files as it has directories and subdirectories , there is only one machine.config file per machine.
The Machine.config file is located in the folder %windir%\Microsoft.NET\Framework\%version%\config, where %version% is a folder that is named for the current installed version of the .NET Framework. Machine.config file contains the default configuration information for every web application, as well as other application types, on the machine. The machine.config file is processed first and any values specified within the machine .config file are inherited throughout every ASP.NET application on your Web server.
2.3  How to Web.Config
The web.config file is a text file which contains XML elements that affect the behavior of an application. It is efficient to store application-level configuration settings in XML-based files that are cached at runtime. Every ASP.NET application contains its own Web.config file , which resides in the root of the application.
The Web.config file overrides many of the settings in Machine.config, within the scope of the specific ASP.NET application where the Web.config file resides. The default Web.config file created by Visual Studio contains comments specific to the most commonly used settings. These comments provide guidance for using the available parameters for a given configuration element . ASP.NET enables you to manage the entire security configuration from the Web.config file.
2.4  Elements in a web.config File
The web.config file is a text file which contains XML elements that affect the behavior of an application. The following are some of the mportant tags in a web.config file.
<configuration> :    In a Web.config file, all the configuration information for an ASP.NET application must reside between the      <configuration> and </configuration> tags. This is the root node, which contains         the declaration of all other             sections of the Web.config file.
<appSettings>  :       This section of the Web.config file provides a way to define custom application settings for an application. The section    can have multiple <add> subelements.   
<appSettings> <add key="connectionstring" value="localhost;uid=readonly;pwd=user"/>             </appSettings>
<compilation> : This element sets several compilation settings for the  application. Some of the settings involve setting a default  language and debug option for the application setting. Debug pages are larger and execute more slowly, so you should use them  only for testing purposes. This section also provides support for the <compilers>, <assemblies> , and <namespaces> subelements. <namespaces>  :            This subelement is used to add or remove namespace references for             assemblies that must be made available when compiling Web pages.
<authentication> :  The <authentication> element sets the authentication policy for  the application. Possible modes are "Windows," "Forms,"  "Passport," and "None."
 <pages> : The <pages> element allows configuration of page  application specific settings.  
<customErrors> : The <customErrors> element provides a means for defining custom    error messages for an ASP.NET application. This is generally used to point users to a friendlier message than the default error messages. The <customErrors> element section supports multiple <error> subelements that are used to define custom errors.     

ASP.NET Introduction

1 ASP.NET Introduction
·          1.1  What isASP.NET ?
·          1.2  Asp.Netand .Net Framework
·          1.3  FirstAsp.Net Program
·          1.4  Deployan ASP.NET Web Application

ASP.NET Tutorial , Help and Source Code in VB.NET and C#

·        ASP.NET is a technology for developing, deploying, and running Web applications.
·        ASP.NET is a part of the Microsoft .NET Framework, so all .NET Framework features are available to ASP.NET applications.
·        ASP.NET web pages are simply pure text, like HTML files.
·        ASP.NET web pages are the main building block for application development.
·        You can develop your applications in any language compatible with the common language runtime, including Microsoft Visual Basic and C#.
·        These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance, and so on.
·        ASP.NET incorporates all the important standards of our time, such as XML and SOAP, plus with ADO.NET and the foundation class libraries.
·        Visual Studio .NET is an excellent development tool for constructing ASP.NET web applications.
·         It provides all of the necessary tools and support for creating ASP.NET web applications.
·        ASP.NET web applications are hosted by Internet Information Server (IIS), which accepts requests from clients and optionally authenticates them before passing the requests on to  Web application. From the following chapters you can learn more about ASP.NET technology in detail.

1.1 What is ASP.NET ?
·        ASP.NET introduces entirely a new object-oriented execution model. In order to overcome the limitations of ASP (Active Server Pages) ,
·        Microsoft has developed a new technology called Microsoft ASP.NET . ASP.NET is more than just the next version of ASP technology, using its mature programming languages VB.NET and C#.
·        ASP.NET is built on the Common Language Runtime (CLR), allowing programmers to write ASP.NET code using any supported .NET languages like VB.NET and C#.
·        Unlike the ASP runtime, ASP.NET uses the Common Language Runtime (CLR) provided by the .NET Framework.
·        The Microsoft .NET Platform provides all of the tools and technologies that are needed to build distributed Web applications.
·        ASP.NET is integrated with Visual Studio .NET, which provides a GUI designer, a rich toolbox, and a fully integrated debugger.
·        In ASP.NET, you can write the HTML code in the .aspx file and the code for programming logic in the code-behind file (.aspx.vb or .aspx.cs ).
·         Also ASP.NET introduces two sets of controls, the HTML controls and the Web controls, which are collectively known as "server controls."
1.2  Asp.Net and .Net Framework
The .NET Framework is an essential technology for ASP.NET development. It provides the basic system services that support ASP.NET, as well as Windows Forms development, the new rich client development technology provided by .NET. The .NET Framework consists of two main parts:
1. The common language runtime : It provides a run-time environment for the execution of code written in any .NET language.
2. The .NET Framework class library : It is designed to support the efforts of developers by providing base classes from which developers can inherit.
1.3 First Asp.Net Program
ASP.NET is integrated with Visual Studio .NET, which provides a GUI designer, a rich toolbox, and a fully integrated debugger. In ASP.NET, you can write the HTML code in the .aspx file and the code for programming logic in the code behind file (.aspx.vb or .aspx.cs ) depends on which .Net language you are selected.         Web Forms allow you to apply Rapid Application Development techniques to building web applications. Simply drag and drop controls onto your form, double-click on a control, and write the code respond to the associated event. You can program ASP.NET in any language that supports the .NET CLS.
Select Visual Studio from Startà All Programs . Select New Web Site from File menu of Visual Studio.  Then you can see a window similar to the following image.




Select ASP.NET Web Site from the New Web Site dialog box. The Name and Location edit fields will contain default values. If you want to change the name , you can do it by editing the Location field. From this dialog box you can select which language (C# or VB.NET) you want to develop ASP.NET website. You can select your convenient language from the Language combobox.
After click the OK button you will get a blank form. You can select controls from the Toolbox which is located left side to the blank form.
Click on the Label control and drag it to the design surface. It will automatically go to the upper-left corner of the design surface and contain the word Label.
Select the label control and change the Text property of label control to "This is my first asp.net program". The property window is placed right side down of your Visual Studio Environment.

After the coding, press F5 to run the web application. When either the C# or VB.NET version is run, it will look like the browser shown.
1.4 Deploy an ASP.NET Web App
When you want to deploy your ASP.NET program on IIS, all you need to do is set up an IIS virtual directory on the target machine and copy the application files to it. You can simply copy the application files to the directory structure on the production server, using one of the following tools:
 
1. The XCOPY command-line tool can copy files from one computer to another on an intranet or internal network.
2. Windows Explorer can copy files from one computer to another on an intranet or internal network.
3. You can use the FTP tool of your choice to copy  application files from one computer to another over the Internet.
4. If your application has been developed using Visual Studio .NET, you can use the Copy Project command to copy files from one computer to another on an intranet or internal network.