ASP.NET Dynamic Styles Response and Request Objects.

60
ASP.NET Dynamic Styles Response and Request Objects

Transcript of ASP.NET Dynamic Styles Response and Request Objects.

Page 1: ASP.NET Dynamic Styles Response and Request Objects.

ASP.NET

Dynamic Styles

Response and Request Objects

Page 2: ASP.NET Dynamic Styles Response and Request Objects.

Dynamic Styles

DHTML is a browser phenomenon, using JavaScript to manipulate the properties and methods of HTML tags in response to user or browser events.

Under ASP.NET these same style settings can take place, in this case through server scripts rather than browser scripts

Page 3: ASP.NET Dynamic Styles Response and Request Objects.

Dynamic Styles

<SCRIPT language="javascript">function Format()

{document.all.BROWSERButton.style.backgroundColor = "#FF0000“document.all.BROWSERButton.style.fontFamily = "comic sans ms“document.all.BROWSERButton.style.fontSize = "12pt“document.all.BROWSERButton.style.width = "150px“document.all.BROWSERButton.value = "Thank You"

}</SCRIPT>

<input id="BROWSERButton" type="button" value="Click Me" onClick="Format()“ style="background-color:steelblue; color:#FFFFFF; font-family:arial; font-size:10pt; width:100; cursor:hand">

Page 4: ASP.NET Dynamic Styles Response and Request Objects.

Built-in ASP Objects

Response Object– Send text, data and cookies to the browser and

control each stage of transmitting the page

Server Object– Overall scripting control, set the timeout variable

for the script

Request Object– Read submitted form data, cookies and server

variables

Page 5: ASP.NET Dynamic Styles Response and Request Objects.

Built-in ASP Objects

Session Object– Allows to attach data to a specific user browsing the

site that is isolated and invisible to other users (user session is identifiable by the cookie that is sent every time a user makes a request) (stay active by default until 20 minutes after the user’s last request or until the session is explicitly abandoned through the code)

Application Object– Allows to manipulate global data in the script that will be

visible to all users browsing the site (ASP application itself)

Page 6: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT

Gives control over what data and data types sent to the client in the headers of HTTP response

Gives control over what data and data types sent to the client in the body of HTTP response

Gives control over when and how data is sent

Page 7: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT- Properties/Methods

Response.IsClientConnected Whether a client browser is still connect to a Web page:True

Response.Redirect("url") Immediately redirects to and loads a different Web page.

Response.Write(content) Writes text or variables to a Web page:Response.Write("Text string"): Text string.

Page 8: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT – Write (ASP)

Writes information directly to the HTTP response body.

<%

Response.Write “<table border=1>”

Response.Write “<tr>”

Response.Write “<td>”

Response.Write “Hello”

Response.Write “</td>”

Response.Write “</tr>”

Response.Write “</table>”

%>

Page 9: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT – Write (.NET)

Response.Write() statements are placed throughout a script to trace the processing sequence and to write the contents of a variable.

<SCRIPT runat="server">Sub ProcessThis (Src As Object, Args As EventArgs)  Response.Write("Start of ProcessThis" & "<br>")  ...  ...  Response.Write("End of ProcessThis" & "<br>")  ProcessThatEnd Sub

Page 10: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT – Write (.NET)

Sub ProcessThat  Response.Write("Start of ProcessThat" & "<br>")  Dim VarA = "Howdy"  ...  ...  Response.Write("Value of VarA = " & VarA & "<br>")  Response.Write("End of ProcessThat" & "<br>")End Sub

</SCRIPT>

Page 11: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT – Write (.NET)

<asp:Button Text="Trace" OnClick="ProcessThis" runat="server" />

Result:Start of ProcessThisEnd of ProcessThisStart of ProcessThatValue of VarA = HowdyEnd of ProcessThat

Page 12: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT - Redirect

Redirects the client’s request to another URL.

Response.Redirect “http://www.mis.boun.edu.tr”

Response.Redirect “x.asp”

x.asp resides in the same folder as the requested page

If the script has written any content to the HTTP response body, that content is ignored by the script once the call to the Redirect method is executed.

Page 13: ASP.NET Dynamic Styles Response and Request Objects.

Response.Redirect (ASP)

<% Response.Redirect "http://www.mis.boun.edu.tr" %>

<HTML> <BODY> xx </BODY> </HTML>

Page 14: ASP.NET Dynamic Styles Response and Request Objects.

Response.Redirect (.NET)

<SCRIPT runat="server">

Sub GoBack (Src As Object, Args As EventArgs)  Response.Redirect("aspnet02-06.aspx")End Sub

</SCRIPT>

<asp:Button Text="Go Back" OnClick="GoBack" runat="server" />

Page 15: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT - IsClientConnected

The Response.IsClientConnected property is useful when you need to make sure that the visitor is still connected to your Web site.

This issue arises when, say, you are conducting e-commerce with a customer. If you have just completed processing a set of transactions for a purchase being made, you might wish to check that the customer has not abandoned your site before finalizing those transactions.

Page 16: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT - Buffer

Determines whether the content created by the script is delivered to the client browser as a whole or send immediately to the client browser as each line is created and entered into the HTML stream

If set to TRUE, then all script on the page is run before the results of that script are sent to the client browser

<% Response.Buffer = True %>

Page 17: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT - Clear

Empties the current contents of the Response buffer.

It does so without sending any of the buffered response to the client.

Page 18: ASP.NET Dynamic Styles Response and Request Objects.

RESPONSE OBJECT - End

Ends all storage of information in the response buffer and sends the current contents of the buffer immediately to the client.

Any code present after the call to the End method is not processed.

Page 19: ASP.NET Dynamic Styles Response and Request Objects.

Response.Buffer/Clear/End

<% Response.Buffer = True %> <HTML> <BODY> <% Dim err err = 1 If Err <> 0 Then

Response.Clear Response.Write "Error Created" Response.End

End If %>

Page 20: ASP.NET Dynamic Styles Response and Request Objects.

Example: Get System Time (ASP)

<% LANGUAGE=“VBSCRIPT” %>

<html> <body>

<% If Minute(Now) < 30 Then %>

Before Half

<% Else %>

After Half

<% End If %>

of

<% response.write (Hour(Now)) %>

</body> </html>

Screen:

After half of 9

Source:

<html> <body>

After Half

of

9

</body> </html>

Page 21: ASP.NET Dynamic Styles Response and Request Objects.

Example: System Time

<% when=now() twoweekslater=dateadd("w",2,when)monthlater=dateadd("m",1,when)sixminuteslater=dateadd("n",6,when)sixhourslater=dateadd("h",6,when)response.write "Now <b>" & when & "</b><br>" response.write "1 month from Now <b>" & monthlater &

"</b><br>" response.write "2 weeks from Now <b>" & twoweekslater &

"</b><br>" %> six minutes from now <b><%=sixminuteslater%> </b><br> six hours from now <b><%=sixhourslater%> </b><br>

Page 22: ASP.NET Dynamic Styles Response and Request Objects.

ASP - REQUEST OBJECT

CollectionsForm (POST)Server VariablesQueryString (GET)CookiesClientCertificate

MethodBinaryRead

PropertiesTotalBytes

Page 23: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- HttpRequest Class

HttpRequest class provides a Request object that contains information about a URL request issued for a Web page.

In general, the Request object pertains to Web page input, with a set of properties that provide information about the URL request received by the page

Page 24: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- ServerVariables

Contain several predefined environment variables in the context of the client’s specific HTTP request of the web server.

Page 25: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- ServerVariables

<SCRIPT runat="server">

Sub Page_Load

  Browser.Text = Request.Browser.Browser  BrowserVersion.Text = Request.Browser.Version  BrowserPlatform.Text = Request.Browser.Platform

End Sub

</SCRIPT>

Page 26: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- ServerVariables

<html><body>

<h3>Properties of your request for this page:</h3><b>Browser Type: </b><asp:Label id="Browser" runat="server"/><br><b>Browser Version: </b><asp:Label id="BrowserVersion" runat="server"/><br><b>Browser Platform: </b><asp:Label id="BrowserPlatform" runat="server"/><br>

</body></html>

Page 27: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- ServerVariables

Output of the script is shown below:

Properties of your request for this page:

Browser Type: IEBrowser Version: 6.0Browser Platform: WinXP

Page 28: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.UserAgent PropertiesThe full identification of the browser requesting the page:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)

Request.Browser.Browser The type of browser making the request:IE

Page 29: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.Browser.Type The type and major version of the browser making the request:IE6

Request.Browser.Version The major and minor versions of the browser request:6.0

Page 30: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.Browser.MajorVersion The major version of the browser making the request:6

Request.Browser.MinorVersion The minor version of the browser making the request:0

Page 31: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.Browser.AOL Whether this is an AOL browser:False

Request.Browser.Frames Whether the browser supports frames:True

Request.Browser.JavaScript Whether the browser supports JavaScript:True

Page 32: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.Browser.Platform The type of operating system under which the browser is running:WinXP

Request.IsSecureConnection Whether the current connection uses a secure Web protocol:False

Page 33: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.UserHostAddress The IP address from which the browser is requesting the page:193.140.202.80Server Properties

Request.ServerVariables ("LOCAL_ADDR")The IP address of the server hosting the requested page.168.16.176.28

Page 34: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.Url.Host The URL of the server hosting the requested page:it.maconstate.edu

Request.RawUrl The portion of the URL request following the domain information:/Tutorials/ASPNET02/aspnet02.aspx

Request.Url.Scheme The type of URL request:http

Page 35: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.Url.Port The port through which the URL request is made:80

Request.ApplicationPath The virtual path to the root directory containing the page requested by the browser:/Tutorials

Request.FilePath The virtual path to the page requested by the browser:/Tutorials/ASPNET02/aspnet02.aspx

Page 36: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Browser Properties

Request.PhysicalApplicationPath The physical path to the root directory of the page requested by the browser:D:\Tutorials\

Request.PhysicalPath The physical path to the page requested by the browser:D:\Tutorials\ASPNET02\aspnet02.aspx

Page 37: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- ServerVariables

Possible Keys: REMOTE_ADDR: TCP/IP of the client REMOTE_HOST: The IP address from which the

web server receives the request REQUEST_METHOD: Get, Post, etc. SERVER_NAME: Web server’s TCP/IP HTTPS: “ON” if the client’s request is using SSL. ALL_HTTP: One long string containing al the HTTP

headers send by the client’s browser.

Page 38: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- ServerVariables

Possible Keys: LOGON_USER: Windows NT account with which the

user has logged onto the system URL: The base URL requested by the client in its

HTTP request. SERVER_PORT: The server port to which the client’s

HTTP request is sent.<%

Dim strUserName

strUserName=Request.ServerVariables(“LOGON_USER”)

%>

Page 39: ASP.NET Dynamic Styles Response and Request Objects.

Get IP

<HTML> <BODY> <% Dim strUserName

strUserName=Request.ServerVariables("REMOTE_ADDR")

Response.Write strUserName %> merhaba </BODY> </HTML>

Page 40: ASP.NET Dynamic Styles Response and Request Objects.

GET vs. POST

GET can be used to retrieve any document, POST cannot

GET and POST can be used to pass data to the object indicated by the URL

When POST is used, the data is passed to the server in the body of the request message

When GET is used, the data is included in the URL as argument string and needs to be parsed

Page 41: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT- Form (POST)

User enters input into the fields of a form When form is submitted, data in each

field is transferred to the server, and then to ASP

Data is sent in the format:name = value

name (attribute of <INPUT>)

Page 42: ASP.NET Dynamic Styles Response and Request Objects.

HTTP Request Header

Create the form:

<html> <body> <h2> Sample Order </h2>

<form method=“post” action=“response.asp”>

<p> First Name: <input name = “fname” size=“48”>

<p> Last Name: <input name = “lname” size=“48”>

Page 43: ASP.NET Dynamic Styles Response and Request Objects.

HTTP Request Header

<p> Title: <input name=“title” type=radio

value=“mr”> Mr.

<input name=“title” type=radio value=“ms”> Ms.

<p> <input type=submit> <input type=reset>

</form> </body> </html>

Page 44: ASP.NET Dynamic Styles Response and Request Objects.

Response.asp

* You should use the Form collection of the Request object to manipulate information

<% title = request.form(“title”)

lastname = request.form(“lname”)

If title= “mr” Then %>

Mr. <% = lastname %>

<% ElseIf title = “ms” Then %>

Ms. <% = lastname %>

<% Else %>

<% = request.form (“fname”) & “ “ & lastname %>

<% End If %>

Page 45: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT-TotalBytes

TotalBytes property is a read-only value that specifies the total number of bytes posted to the web server by the client in the HTTP request body.

Var = Request.TotalBytes

Page 46: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT-Client Certificate

Provides access to the certification fields of the client’s digital certificate.

Client certificates are sent to the web server when a client’s browser supports the Secure Sockets Layer and that browser is connected to a web server running the SSL (https://).

Request.ClientCertificate

Page 47: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT-Client Certificate

Subject: A list of comma-delimited strings that provide information about the owner of the digital certificate.

Issuer: Information about the issuer.

ValidFrom and ValidUntil: Validation dates

SerialNumber: An ASCII representation

Ex: 0A-B7-34-23

Certificate: A string value that contains the entire binary stream from the certificate content.

Flags: Provide additional information such as presence of certificate.

Page 48: ASP.NET Dynamic Styles Response and Request Objects.

REQUEST OBJECT-Client Certificate

Request.ClientCertificate (“IssuerC”)

Retrieve the country of origin for the Issuer.

Request.ClientCertificate (“SubjectO”)

Retrieve the organization of the Subject.

Page 49: ASP.NET Dynamic Styles Response and Request Objects.

Session Tracking

HTTP is a stateless protocol that does not support persistent connections that would enable Web servers to maintain state information regarding clients.

A session ID represents a unique client on the Internet. If the client leaves a site and returns later, the client will still be recognized as the same user.

To help the server distinguish among clients, each client must identify itself to the server.

The tracking of each individual clients, known as session tracking, can be achieved in a number of ways.

Page 50: ASP.NET Dynamic Styles Response and Request Objects.

Session Tracking

Session tracking ways:1. Use of input form elements of type hidden and

sending them to the form handler on the Web server.

2. Use of HttpSessionState object

3. Cookies

Page 51: ASP.NET Dynamic Styles Response and Request Objects.

Cookies

Cookie: Small pieces of information stored by the web server on the web client’s machine.

This information is sent to the server each time the client requested a page from the same area from which the information was received.

A cookie is a text file.

Page 52: ASP.NET Dynamic Styles Response and Request Objects.

Cookies

Domain: Returns a String containing the cookie’s domain. This determines which web server can receive the cookie.

Expires: Returns a DateTime object indicating when the browser can delete the cookie.

Name: Returns a String containing the cookie’s name.

Page 53: ASP.NET Dynamic Styles Response and Request Objects.

Cookies

Path: Returns a String containing the URL prefix for the cookie.

Secure: Returns a Boolean value indicating whether the cookie should be transmitted through a secure protocol. The value True causes a secure protocol to be used.

Value: Returns a String containing the cookie’s value.

Page 54: ASP.NET Dynamic Styles Response and Request Objects.

Cookies

Send Cookie

Response.Cookies("Cust").Name="BE"

Response.Cookies("Cust").Expires=time.AddDays(10)

Get Cookie

Request.Cookies("Cust")

Delete Cookie

Response.Cookies("Cust").Expires = Date – 365

' Deleted by setting expiration date to a past date

Page 55: ASP.NET Dynamic Styles Response and Request Objects.

Session

A user Session is created by ASP.NET whenever a visitor arrives at any Web page located in your root application directory.

A Session Object maintains identification information about the visitor and allows ASP.NET to differentiate between visitors and their browsing status as they navigate the Web site.

Page 56: ASP.NET Dynamic Styles Response and Request Objects.

SessionID

Your visit to this site, for instance, can be identified by the SessionID value,

Session.SessionID = "filyqavdzfnqrj45ofykaeel" SessionID value is a random number that was

generated when you first arrived at the site. Session remains alive until 20 minutes after your last

interaction with a page or until you close your browser. A revisit generates a new SessionID number.

Page 57: ASP.NET Dynamic Styles Response and Request Objects.

Session Variable

The Session Object also serves as a global storage area that scripts can use to maintain data values between pages.

A Session variable is created by assigning a value to a name:

Session("name") = "value"

Page 58: ASP.NET Dynamic Styles Response and Request Objects.

HttpSessionState Properties

Count: Specifies the numebr of key-vaue pairs in the Session object.

IsNewSession: Indicates whether this is a new session.

IsReadOnly: Indicates whether the Session object is read only.

Keys: Returns an object containing the Session object’s keys.

Page 59: ASP.NET Dynamic Styles Response and Request Objects.

HttpSessionState Properties

SessionID: Returns the session’s unique ID.

Session.SessionID

Timeout: Specifies the maximum number of minutes during which a session can be inactive before the session expires.

Session.Timeout

Session.Add(“TR”,”2005”)

Store in session as name-value pair

Page 60: ASP.NET Dynamic Styles Response and Request Objects.

HttpSessionState Properties

SessionID: Returns the session’s unique ID.

Session.

Timeout: Specifies the maximum number of minutes during which a session can be inactive before the session expires.

Session.Timeout