Pages

13 June 2011

2.1.1)Importance of ViewState

View State in a mechanism used by ASP.NET to store  user specific and response data between pages request. The data being stored is typically associated with the server controls. This data is referred to as control state.

View state data is not stored by server but by a web page instead. More on (4.)

2.1.0) Life Cycle of ASP.NET Web Page.


Page Life Cycle events:

Init
InitComplete
PreLoad
Load
Control(PostBack)
LoadComplete
SaveStateComplete
Render


09 June 2011

2.0.0) Server Controls

Server controls are tags that are understood by the server.
This provides both functionality adn programmability through server side model eg:

<asp:control_name id="some_id" runat="server" />


All server control including web page itself , inherits from System.Web.UI.Control class.

 There are 2 primary types of server controls:
HTML and Web Controls.
HTML Control :  This provides server side processing that generally map back to HTML
Web Control:  These are ASP.NET controls that focus more on their object model and less on their HTML rendering.


Web server controls may render differently according to the browser .

07 June 2011

1.3.1) Web. Config File

WSAT : Website administration tool 

1.3.0) Web Configuration files(.config)

The configuration files allow management of settings to a site. These files are XML with .config as extension. Elements such as settings,database connection string, caching settings etc are included in this file.
A website may have more than one configuration files.

The configuration files are applied to site based on hierarchy. There is  a global configuration file on a given machine for all the sites called Machine.Config(%SystemRoot%\Microsoft.NET\Framework\<versionNumber>\CONFIG\directory)

The Machine.config file contains settings for .NET application types. Some settings may be overridden by Web.config.
The config file hierarchy :




06 June 2011

1.2.2) Website Compilation

Most applications are not precompiled. These pages and the codes are copied to the web server and then dynamically compiled by the web server the first time they are requested by a user. On compilation the code is placed inside an assembly and loaded into your site's application domain. Any user hence wanting the same page the same code will be served by the compiled assembly.

This is refereed to as a dynamic compilation.

1.2.1) The Anatomy Of ASPX

A tipical ASPX page include three sections: page derictives, code and page layout.

  1. Page directives: This section is used to set up the environment which specifies how the page should be processed.
  2. Code: This section contains code to handel the events that execute in the server based on the ASP.NET page processing model.(.cs for C# and .vb for Visual basic)(This may be in a seperate page or you can specify the code in the same page using the tag with the attribute runat="server".
  3. Page Layout: The Page layout is written using the HTML. This includes the HTML body, markup and the style information.
Example:
1)
<%@ Page Language="VB" %>
<"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--code-->
<script runat="server">
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Label1.Text = "Hello World!"
End Sub
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</div>
</form>
</body>
</html>
Single File VS Code- Behind Pages:
In single file model the compiler generates a new class for the page which inherits the Page Class.
The Code-Behind pages are physically separated from the user interface layout. This makes it easier to work with. The code is stored as a partial class that inherits from the Page class. Simplyfing the maintainance of the page as you do not have to keep page initialization information in a separate partial class as visual studio takes care of it. 

05 June 2011

1.2.0) Creating Websites

2.1) Creating a New website and Adding New pages.

Webproject in Visual studio (VS) contains the folders and files(resources) that define Websites.

Creating a Web Site Project in Visual Studio:

1.) In Visual Studio choose File->New->Website
2.)Select Website type,location and programming language I am using Visual basic as the programming language and you may use c# as you feel comfortable.
3.)The hit OK.

This will create a File System for the website which will run locally using ASP.NET web server.(This is for development Options once the full project is finished you can port it over using FTP or any other transfer protocol to your actual production web server)

You may even use FTP based web development using a development server. Please contact your server admin to get details how you can log in to create a file system in the Development environment.

Creating a Web Application Project in Visual Studio:

Visual Studio provides another means of creating a website project using Web application Project. This can be used if you want to add new web application to an existing project.

Contents Of the Newly Created Site

ASP.NET adds specific folders with special user permission for specific files. Like App_Data which will be used to databases such as Microsoft SQL .mdf file. A user trying to access this folder will get permission error(HTTP 403 forbidden error).

Folders
  1. App_ Browser
  2. App_Code
  3. App_Data
  4. App_GlobalResources
  5. App_LocalResources
  6. App_Themes
  7. App_WebReferences
  8. Bin

Adding Web page :
Asp.NET Websites contain Web Form as their files which is a single file or a pair of files.
  1. On the Solution Explorer(Generally on the Right side of the window). Right click and click on Add New Item.
  2. In the New Item Dialog box click on web form
  3. Select the programming language for the form
  4. The Check the boxes indicatiog if it is a pair of files using Place Code in the Separate check box.



04 June 2011

1.1.3) GET POST and Query Strings

Data between a client can be sent to the server via a form or form tags in html.

The attribute method in the form tag has values GET and POST.

When the GET is used the form data is appended to the URL as a part of the query string. When the GET verb is used the data is appended to the URL as a part of the query string as a key-value pair separated by the " & "ampersand character.

ex: www.alenrk.com/pagename.aspx?Param1=value1&Param2=value2
Which is thrown to the server in the form of
GET /pagename.aspx?Param1=value1&Param2=value2
Host : www.alenrk.com

The GET method is used when you want the user to see the parameters . Do not use GET method when passing sensitive information.

For all sensitive information the POST method is used.POST removes size constraint. When the POST verb is used the data is placed into the message body of the request as follows:

POST /pagename.aspx HTTP/1.1
Host: www.alenrk.com

Param1=value1&Param2=value2

Sending data back to the server as a part of your request is reffered as a PostBack in ASP.NET.

ASP.NET Get may also be used for PostBack. Pages contain a property called IsPostBack that is used to determine if the data is a being sent back to the server or if the web page is simply being requested.

03 June 2011

1.1.2) Introduction

2.) Introduction to ASP :

Statelessness : Stateless :: When a web server receives a request from a client machine via HTTP then a response is sent back. After this response the web server closes any connection between it and the browser and releases all resources that were involved with this request. This type of application is considered stateless as no data was held by the web server between request.

Static web pages (Old View of how a web server worked)
Web browser --------------- Web server

1.)HTTP get -------------->> 2.)Processes the Get request
4.)Displays Page <<-------- 3.)Sends Response and Closes Connection Dynamic Web Pages Web Browser ---------------- Web Server 1.) HTTP GET ---------------->> 2.) Process GET request
3.) Execute Server-side code (Store Session Data)
5.) Display Page<<------------- 4.)Send Response Web Browser : It is platform independent and displays the webpages. Web browsers now can process client side scripts like VB script or JavaScript and also run partial page request via AJAX/Silverlight/Flash.

HTTP : It is a text based communication protocol. Uses port 80 or 443 for https

When a URL is requested by the browser a GET command is fired up with the page and version. ex GET /default.aspx HTTP/1.1 Host: www.somethingsomething.com

DAV : Distributed Authoring and Versioning

More HTTP methords
OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, TRACE, CONNECT, DEBUG

REQUEST : Communication from a web browser to a web server in ASP.NET. In ASP.NET there is a Request Object used to represent web browsers communication to web server.
It may be use to associate cookies, query strings, etc.

RESPONSE : Communication from web server back to a web browser. Resources for a response is wrapped in a RESPONSE object.

The response also includes a status code.

Status code Description
1xx Informational: Request received continuing process.
2xx Success: The action was received, understood,accepted
3xx Redirect Command:Further action must be taken to complete request
4xx Client Error: Server doesnt know how to fulfill request.
5xx Server Error: The server failed to fulfill a request that appears valid.

: Interesting Speed Race Controlled Speed :

MIME type : text, image. audio, video, application
MIME list in HKEY_CLASSES_ROOT\MIME\Database\Content Type

1.) Web sense

1.) ASP.Net starting: From (MCTS EXAMS 70-562) - 3

Web application are hosted on a web server and the process via which a client visits a website may be defined in the following process.

1.) User uses a web browser to iniate a request foe a web server resource
2.) Http is used ti send a GET request to the Web server
3.) The web server processes the Get resuest on the server.(Locates the file and runs the code)
4.) The web server then sends a response back to the web Browser.