Friday, August 6, 2010

The Anatomy of an ASPX Page

The Anatomy of an ASPX Page

A page in ASP.NET contains user interface layout information, code that executes on the server, and directives to both connect the layout with the code and to tell ASP.NET how the page should be processed. The standard ASP.NET page has an .aspx extension. The typical .aspx page includes three sections: page directives, code, and page layout.

Page directives This section is used to set up the environment, specifying how the page should be processed. For example, this is where you can indicate an associated code file, development language, transaction, and more.

Code This section contains code to handle events that execute on the server based on the ASP.NET page processing model. By default, Visual Studio creates a separate file that contains your code. This is called a code-behind file and is attached to the .aspx page.

Page layout The page layout is written using HTML. This includes the HTML body, markup, and style information. The HTML body may contain HTML tags, Visual Studio controls, user controls, and simple text.

Thursday, August 5, 2010

Creating ASPX Pages

Creating ASPX Pages

Once your Web site has been created, the next step is to begin adding pages to the site. An ASP.NET page is also known as a Web Form and can be composed of a single file or a pair of files. The steps for adding a new Web page to a Web site are as follows:

1. Using the Visual Studio 2008 menus, request a new Web Form. Typically this is done inside Solution Explorer by right-clicking the Web site and selecting Add New Item.

2. In the Add New Item dialog, assign a name to the Web Form.

3. Select the programming language for this Web Form.

4. Indicate if the page is self-contained or uses a pair of files using the Place Code In Separate File check box.

The Place Code In Separate File check box allows you to indicate whether your page should be made up of a single, self-contained file or a pair of files (HTML layout and an associated code-behind file).

The Content of a Newly Created Web Site

The Content of a Newly Created Web Site:

App_Browsers: Contains browser definition files (.browser) that ASP.NET uses to identify browsers and determine their capabilities. These files are often used to help support mobile applications

App_Code Contains source code for classes and business objects (.cs, .vb, and .jsl files) that you want to compile as part of your application

App_Data Contains application data files (.mdf and .xml files).

App_GlobalResources Contains resources (.resx and .resources files) that are compiled into assemblies and have a global scope. Resource files are used to externalize text and images from your application code. This helps you support multiple languages and design-time changes without recompilation of source code

App_LocalResources Contains resources (.resx and .resources files) that are scoped to a specific page, user control, or master page in an application.

App_Themes Contains subfolders that each define a specific theme (or look) for your site. A theme consists of files (such as .skin, .css, and image files) that define the appearance of Web pages and controls.

App_WebReferences Contains Web reference files (.wsdl, .xsd, .disco, and .discomap files) that define references to Web services.

Bin Contains compiled assemblies (.dll files) for code that you want to reference in your application. Assemblies in the Bin folder are automatically referenced in your application.

Creating a Web Site Project & Web Site Solution Files

Creating a Web Site Project

You can create a new Web site project directly from Visual Studio 2008. The basic steps for doing so are as follows:

1. In Visual Studio 2008, use the File menu to create a new Web site (File
Website). This launches the New Web Site dialog box.

2. Select the Web site type, location, and default programming language.

3. You might also wish to select the target framework for your project. New to Visual Studio 2008 is the ability to code against multiple versions of the Microsoft .NET Framework. You can choose among versions 2.0, 3.0, and 3.5.

4. Once defined, click OK to finish setting up your site

Web Site Solution Files

When a Web site is created, Visual Studio creates a solution file (.sln) and a hidden solution user options file (.suo). The solution file is a text file that contains information such as the following:

• A list of the projects that are to be loaded into Visual Studio 2008 to make up the entire solution.

• The target framework version for the solution.

• The default language for the solution.

By default, these files are created in the Documents\Visual Studio2008\Projects folder for Web sites.

Creating Web Sites in Visual Studio 2008

Creating Web Sites

The Visual Studio 2008 project system allows you to define a new Web site project based on how you intend to access the site content from a Web server. You can create a Web project connected to a file-system–based server on your computer, an IIS server, or an FTP server.

File system: The file-based Web site stores all of the files for the Web site inside a directory of your choosing. This Web site uses the lightweight ASP.NET development server that is included in Visual Studio 2008.

Ftp: The FTP-based Web site is useful when you want to connect to your site via FTP to manage your files on a remote server. This option is typically used when your Web site is hosted on a remote computer and your access to the files and folders on that server is through FTP.

http: An HTTP-based Web site is used when you are working with a site deployed inside of IIS (either locally or on a remote server). This Web site may be configured at the root of the IIS Web server, or in a virtual directory that is configured as an application

Introduction to Web server, web browser and HTTP

Introduction to Web server, web browser and HTTP

A web application is unlike a standard Windows application. It does not run in a single process on a single machine. Instead, it is typically hosted on a Web server and accessed via a Web browser on a client machine. The communication between the web server and web browser is sent by using HTTP.

The communication process between browser and server can be categorized into the following steps.

1. A user uses his/her Web browser to initiate a request for a Web server resource.

2. HTTP is used to send a GET request to the Web server.

3. The Web server processes the GET request on the server.

4. The Web server then sends a response back to the Web browser. The HTTP protocol is used to send the HTTP response back to the Web browser.

5. The user’s web browser then processes the response (typically HTML and JavaScript) and renders the Web page for display to the user.

6. The user may then enter data and perform an action such as clicking submit button that cause his/her data to be sent back to the Web server for processing.

7. HTTP is used to POST the data back to the Web server.

8. The web server then processes the POST request.

9. The web server then sends a response back to the Web browser. HTTP is used to send the HTTP response to the Web browser.

10. The web browser again processes the response and displays the Web page to the user. This process is repeated over and over during a typical Web application session.

The Web Server’s Role

The first Web servers were responsible for receiving and processing simple user requests from browsers via HTTP. The Web server handled its request and sent a response back to the Web browser. The Web server then closed any connection between it and the browser and released all resources that were involved with the request

The Web Browser’s Role

The Web browser provides a platform-independent means of displaying Web pages that were written in HTML. HTML was designed to be able to render information on any operating system while placing no constraint on the window size.

Understanding the Role of Hypertext Transfer Protocol

HTTP is a text-based communication protocol that is used to request Web pages from the Web server and send responses back to the Web browser. HTTP messages are typically sent between the Web server and Web browser using port 80, or port 443 when using Secure HTTP (HTTPS).