Professional Documents
Culture Documents
NET
Overview of ASP.NET and Web Forms
Microsoft® ASP.NET is the next generation technology for Web application development. It
takes the best from Active Server Pages (ASP) as well as the rich services and features provided
by the Common Language Runtime (CLR) and add many new features. The result is a robust,
scalable, and fast Web development experience that will give you great flexibility with little
coding.
Web Forms are the heart and soul of ASP.NET. Web Forms are the User Interface (UI) elements
that give your Web applications their look and feel. Web Forms are similar to Windows Forms in
that they provide properties, methods, and events for the controls that are placed onto them.
However, these UI elements render themselves in the appropriate markup language required by
the request, e.g. HTML. If you use Microsoft Visual Studio® .NET, you will also get the familiar
drag-and-drop interface used to create your UI for your Web application.
Web Forms are made up of two components: the visual portion (the ASPX file), and the code
behind the form, which resides in a separate class file.
Browser
IIS
ASP.NET
Web Forms NET Language
Web Controls VB, C#
The Purpose of Web Forms
Web Forms and ASP.NET were created to overcome some of the limitations of ASP. These new
strengths include:
• A rich set of server-side controls that can detect the browser and send out appropriate markup
language such as HTML
• Less code to write due to the data binding capabilities of the new server-side .NET controls
• Compiled code and support for multiple languages, as opposed to ASP which was interpreted
as Microsoft Visual Basic Scripting (VBScript) or Microsoft Jscript®
Types of Controls
1. Server Controls
AdRotator
DataGrid Control
DataList Control
2. Validation Controls
CompareValidator
CustomValidator
RangeValidator
RegularExpressionValidator
RequiredFieldValidator
3. HTML Controls
4. Data Controls.
ASP.NET Server applications are
By using any one of the above mentioned servers, we can perform ASP.NET Page
validations. If there is a Server, we have to start the server. But ASP.NET Servers (both IIS and
PWS) can automatically start and run when the system switched on.
ASP.NET Objects
Request - Used to retrieve Information included with the request from the client.
(Browser to Server)
ObjectContext - Used to initiate and control transactions and create new objects
through Microsoft Transaction Server.
ASPError - Used to obtain information about the errors that occur while the ASP
engine processes a script.
Response Object
Response.Write Method
Response.Cookies Collection
Response.AddHeader Method
Response.Redirect Method
Response.Status Property
Response.End Method
Response.Flush Method
Response.Write Method
Used to write data to client
Response.Cookies Collection
Storage of values temporarily. Keeping a variable values between the pages. Storing
values between the pages is called maintaing state.
Response.AddHeader Method
Eg:
Page_Load()
Response.AddHeader("Refresh","5;url=redipage.aspx");
Response.Write("This page has been redirected after <span id='jtime'> 5 </span> seconds");
<script language=”vbscript”>
window.setTimeout "changeval()",1000,"vbscript"
sub changeval()
dim time
time = document.all.item("jtime").innerText
time = time - 1
document.all.item("jtime").innerText = time
if time > 0 then
window.setTimeout "changeval()",1000,"vbscript"
End if
End Sub
<script>
Response.Redirect Method
Response.Redirect(“filename.aspx”);
LinkButton1_click
{
Response.Redirect("http://localhost/MyAsp/CookieMgmt/Inbox.aspx");
}
Response.Status Property
Eg:
Page_Load()
string ipaddr;
ipaddr = Request.ServerVariables["REMOTE_ADDR"];
Response.Write(ipaddr);
if (!ipaddr.Equals("127.0.0.1"))
{
Response.Status="403 Access Forbidden";
Response.Write(Response.Status);
Response.End();
}
Response.Write("<HTML>");
Response.Write("<BODY>You have accessed this page through the IP Address of
127.0.0.1 </BODY> </HTML>");
Request Object
The request object contains the information that the browser sends to the server. For
every request, the browser include some additional information for communication like
IPAddress, the type of information required, all form content, QueryString variables, browser
type information Etc. Use the request object to read that information.
Request.ServerVariables Collection
This contains standard information automatically sent by the browser for every request.
Some Important Values
APPL_PHYSICAL_PATH - The Physical path of your application. Does not include the
name of the requested file. This value is useful, because you should never hard-code a path in-
your application, if possible.
LOCAL_ADDR - The IPAddress of the server hosting your application.
LOGON_USER - The network username of the browser requesting this resource
PATH_INFO - The Full physical path to the requested file. This value is useful for
redirect.
SERVER_NAME - The name of the server requested by the user. Note that all servers
support localhost.
SERVER_PORT- The IP port number - Usually 80 for HTTP Servers.
HTTP_USER_AGENT - The make and version of the requesting Browser
SessionID - SessionID of the Specific browser
Eg:
Page_Load()
Response.Write("<h2> Request ServerVariables List </h2>");
Response.Write("Application Physical Path : " +
Request.ServerVariables["APPL_PHYSICAL_PATH"] + "<BR>");
Response.Write("Local Addr : " + Request.ServerVariables["LOCAL_ADDR"] + "<br>");
Response.Write("Path Info : " + Request.ServerVariables["PATH_INFO"] + "<br>");
Response.Write("Server Name : " + Request.ServerVariables["SERVER_NAME"] + "<br>");
Response.Write("Server Port : " + Request.ServerVariables["SERVER_PORT"] + "<br>");
Response.Write("Http User Agent : " + Request.ServerVariables["HTTP_USER_AGENT"] +
"<br>");
Request.Cookies Collection
The response.Coookies is write-Only.
The request.Cookies is Read-only
If you set a Response.Cookie, it will appear in the next request from the client browser.
Maximum 1024 Character data's are stored
Syntax
variable = Request.Cookies["variable"].Value
Eg:
Login.aspx
Label -> Username
Label -> Password
TextBox1 -> txtUname
TextBox2 -> txtPword
Button -> btnSubmit -> Submit
Codings
Using System.Data.SqlClient;
SqlConnection con = new SqlConnection("server=server;Database=master;User
id=sa;Password=killer");
string qry = "Select * from UserLogin where username='" + txtUname.Text + "' and pword='" +
txtPword.Text + "'";
SqlCommand cmd = new SqlCommand(qry,con);
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Cookies["username"].Value = txtUname.Text;
Response.Cookies["password"].Value = txtPword.Text;
Response.Redirect("http://localhost/MyAsp/CookieMgmt/Links.aspx");
}
else
Response.Write("Invalid Username and PAssword");
cmd.Connection.Close();
Links.aspx
LinkButton1 -> Inbox
LinkButton2 -> Compose
codings
LinkButton1_click
{
Response.Redirect("http://localhost/MyAsp/CookieMgmt/Inbox.aspx");
}
LinkButton2_Click
{
Response.Redirect("http://localhost/MyAsp/CookieMgmt/Compose.aspx");
}
Inbox.aspx
Page_Load
{
Response.Write("<h1 align=center> Inbox </h1>");
Response.Write("Username : " + Request.Cookies["username"].Value + "<br>");
Response.Write("Password : " + Request.Cookies["password"].Value);
}
Compose.aspx
Page_Load
{
Response.Write("<h1 align=center> Compose </h1>");
Response.Write("Username : " + Request.Cookies["username"].Value + "<br>");
Response.Write("Password : " + Request.Cookies["password"].Value);
}
Application Object
To store global data.
Application object provide our application with global data or information that applies to
all users for our application.
There is only one Application object for all users of your Application.
Introduction to Threads
Web Servers must handle simultaneous request from multiple Users. Sometimes, usage is
slow. To Keep track of request, the web servers puts them in a queue. A queue is a list in which
you add items at on end and remove them at the other end.
Of course, it will not handle multiple threads simultaneously. It uses a time slice method
for equal time sharing for the users.
The ASP.NET Engine, by default starts with three initial threads. It can be increased
based on the processor speed.
Application.Lock Method
Application.UnLock Method
Application Lock / Unlock Method
There's only one application object, shared among multiple users. Any sessions can
access values in the Application Object, but you need to ensure that only one session has
permission to change values at any given time. To do that, You lock the Application before
changing the value and unlock it when you finished your modifications.
Eg:
global.asax.cs
Application_Start()
{
Application["page1"] = 0;
}
WebForm1.aspx.cs
Response.AddHeader("Refresh","5");
int pagecount;
Application.Lock();
Application["page1"] = Int32.Parse(Application["page1"].ToString()) + 1;
pagecount = Int32.Parse(Application["page1"].ToString());
Application.UnLock();
Response.Write("This page has been visited " + pagecount + " times");
Server Object
This Object gives high-level access to the Server.
Using this properties and Methods we can
1. Execute other ASP Files
2. Translate Virtual path to Physical path
3. Perform Server-Side Redirects
Server.ScriptTimeout Property
Server.HtmlEncode Method
Server.Execute Method
Server.Transfer Method
Server.MapPath Method
Server.ScriptTimeOut Property
Specifies the amount of runtime in seconds for a script before it terminates.
Server.HtmlEncode Method
Response.Write(Server.HtmlEncode("<html>"));
Server.MapPath Method
This will map the Physical path of the file.
string physicalAppPath;
physicalAppPath = Server.MapPath("/myasp");
Response.Write("The Physical path is : " + physicalAppPath + "<br>");
Session Object
An ASP.NET Sessions begins at a browser's First request for any ASP.NET page in a
directory marked as an IIS application. The server immediately redirects the user to a file called
global.asax.
Global.asax
Application onStart
Session onStart
Session onEnd
Application onEnd
SessionID Cookie
The server gives the browser a unique token in response to its first request so the browser
can identify itself to the server for subsequent request.
4. Immediately after creates the new Session object, ASP.NET Calls the Session_OnStart
Event
5. When the session times out or you issues the Session.Abandon command, the
ASP.NET engine calls the Session_onEnd event procedure., then destroys the Session Object
6. After the ASP engine destroys the last session object, it calls the Application_OnEnd
event procedure
Session.Abandon Example
global.asax.cs
Application _Start()
{
Application["counter"] = 0
}
Session_Start()
{
Application["counter"] = Int32.parse(Application["counter"].ToString()) + 1
}
WebForm1.aspx.cs
Response.Write("<h1 align=center> Session Abandon Example </h1>");
Response.Write("Your Session ID is : " + Session.SessionID + "<br>");
Response.Write("Application[counter] : " + Application["counter"]);
Session.Abandon();
Response.Write("<p> Your session has been abandoned. Make a note of your SessionID,then
referesh your browser. Each time you referesh this page, you should get a new SessionID.</p>");
Validation Controls
RequiredFieldValidator
Properties
ID -> Name of the Validator
ControlToValidate
ErrorMessage
RegularExpressionValidator
Properties
ID
ControlToValidate
ErrorMessage
Text
ValidationExpression - \d{1,} [0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}
AdRotator Component
Banner.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl> http://localhost/shoba/AdComponent/se_01.gif </ImageUrl>
<NavigateUrl> http://localhost/shoba/CSC/WebForm1.aspx </NavigateUrl>
<AlternateText> The Order Online Form for Webshoppe </AlternateText>
<Impressions> 1 </Impressions>
</Ad>
<Ad> <ImageUrl> http://localhost/shoba/AdComponent/Flowers.gif </ImageUrl>
<NavigateUrl> http://localhost/shoba/CSC/Registration.aspx </NavigateUrl>
<AlternateText> This page is used for Registration </AlternateText>
<Impressions> 2 </Impressions>
</Ad>
</Advertisements>
Distributed Computing
* Improve Performance
* Components are compiled separately -> Business Logic
* Code Reusability
Distributed Technology
1. Sockets
2. RPC -> Remote Procedure call
3. RMI
4. CORBA
5. DCOM
Server Client
Connect
Listen
Accept
Send Receive
Receive Send
RPC -> Remote Procedure Call
* RPC is a layer
* One more layer in OSI model.
* It supports Method invocation
* The data are send and received as a string format
* It doesn't support object transfer.
RMI/CORBA/DCOM
* Enhancement of RPC
* Object transfer is possible.
RMI Registry
Stub Skeleton
Network
CORBA -> Common Object Request Broker Architecture
* Language Independent
* Platform Independent
* Communication two different objects present in two different machines
* IIOP -> Internet Inter ORB Protocol
* COS Registry and COS Naming Service
Web Services
Eg:
Document Object Model (DOM)
Parsing XML document to VB or any other application