ASP.NET Dynamic Styles Response and Request Objects.

Slides:



Advertisements
Similar presentations
E-Commerce CMM503 – Lecture 8 Stuart Watt Room C2.
Advertisements

Maintaining State Between the Client and Server Internet Programming Using VBScript and JavaScript 9.
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Session 13 Active Server Pages (ASP) Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
JavaScript Forms Form Validation Cookies CGI Programs.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Chapter 10 Managing State Information PHP Programming with MySQL.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Chapter 10 Maintaining State Information Using Cookies.
Web Client/Server Communication A290/A590, Fall /09/2014.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Principles of Computer Security: CompTIA Security + ® and Beyond, Third Edition © 2012 Principles of Computer Security: CompTIA Security+ ® and Beyond,
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
State Management. What is State management Why State management ViewState QueryString Cookies.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
Chapter 8 Cookies And Security JavaScript, Third Edition.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Web Form Fundamentals Chapter-2 Unit-2.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Website Development with PHP and MySQL Saving Data.
Chapter 6 Server-side Programming: Java Servlets
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Web Database Programming Week 7 Session Management & Authentication.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
ASP Objects Active Server Pages (cont..) 1. 2 ASP : Objects ASP provides built-in objects for performing useful tasks that simplify web development.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Active Server Pages Session - 3. Response Request ApplicationObjectContext Server Session Error ASP Objects.
ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC.
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HTTP Transactions 1. 2 Client-Server Model 3 HTTP HyperText Transport Protocol Native protocol for WWW Sits on top of internet’s TCP/IP protocol HTTP.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● / www,histpk.org Hidaya Institute of Science & Technology
National College of Science & Information Technology.
WWW and HTTP King Fahd University of Petroleum & Minerals
ASP Explained By: Sarbjit Kaur.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
The Request & Response object
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
Client side & Server side scripting
Chapter 2 Interacting with the Customer
Presentation transcript:

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

Dynamic Styles 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" }

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

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)

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

RESPONSE OBJECT- Properties/Methods Response.IsClientConnectedWhether 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.

RESPONSE OBJECT – Write (ASP) Writes information directly to the HTTP response body. <% Response.Write “ ” Response.Write “Hello” Response.Write “ ” %>

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. Sub ProcessThis (Src As Object, Args As EventArgs) Response.Write("Start of ProcessThis" & " ") Response.Write("End of ProcessThis" & " ") ProcessThat End Sub

RESPONSE OBJECT – Write (.NET) Sub ProcessThat Response.Write("Start of ProcessThat" & " ") Dim VarA = "Howdy" Response.Write("Value of VarA = " & VarA & " ") Response.Write("End of ProcessThat" & " ") End Sub

RESPONSE OBJECT – Write (.NET) Result: Start of ProcessThis End of ProcessThis Start of ProcessThat Value of VarA = Howdy End of ProcessThat

RESPONSE OBJECT - Redirect Redirects the client’s request to another URL. Response.Redirect “ 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.

Response.Redirect (ASP) xx

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

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.

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 OBJECT - Clear Empties the current contents of the Response buffer. It does so without sending any of the buffered response to the client.

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.

Response.Buffer/Clear/End <% Dim err err = 1 If Err <> 0 Then Response.Clear Response.Write "Error Created" Response.End End If %>

Example: Get System Time (ASP) Before Half After Half of Screen: After half of 9 Source: After Half of 9

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 " & when & " " response.write "1 month from Now " & monthlater & " " response.write "2 weeks from Now " & twoweekslater & " " %> six minutes from now six hours from now

ASP - REQUEST OBJECT Collections Form (POST) Server Variables QueryString (GET) Cookies ClientCertificate Method BinaryRead Properties TotalBytes

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

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

REQUEST OBJECT- ServerVariables Sub Page_Load Browser.Text = Request.Browser.Browser BrowserVersion.Text = Request.Browser.Version BrowserPlatform.Text = Request.Browser.Platform End Sub

REQUEST OBJECT- ServerVariables Properties of your request for this page: Browser Type: Browser Version: Browser Platform:

REQUEST OBJECT- ServerVariables Output of the script is shown below: Properties of your request for this page: Browser Type: IE Browser Version: 6.0 Browser Platform: WinXP

REQUEST OBJECT- Browser Properties Request.UserAgentPropertiesThe full identification of the browser requesting the page: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;.NET CLR ) Request.Browser.BrowserThe type of browser making the request: IE

REQUEST OBJECT- Browser Properties Request.Browser.TypeThe type and major version of the browser making the request: IE6 Request.Browser.VersionThe major and minor versions of the browser request: 6.0

REQUEST OBJECT- Browser Properties Request.Browser.MajorVersionThe major version of the browser making the request: 6 Request.Browser.MinorVersionThe minor version of the browser making the request: 0

REQUEST OBJECT- Browser Properties Request.Browser.AOLWhether this is an AOL browser: False Request.Browser.FramesWhether the browser supports frames: True Request.Browser.JavaScriptWhether the browser supports JavaScript: True

REQUEST OBJECT- Browser Properties Request.Browser.PlatformThe type of operating system under which the browser is running: WinXP Request.IsSecureConnectionWhether the current connection uses a secure Web protocol: False

REQUEST OBJECT- Browser Properties Request.UserHostAddressThe IP address from which the browser is requesting the page: Server Properties Request.ServerVariables("LOCAL_ADDR")The IP address of the server hosting the requested page

REQUEST OBJECT- Browser Properties Request.Url.HostThe URL of the server hosting the requested page: it.maconstate.edu Request.RawUrlThe portion of the URL request following the domain information: /Tutorials/ASPNET02/aspnet02. aspx Request.Url.SchemeThe type of URL request: http

REQUEST OBJECT- Browser Properties Request.Url.PortThe port through which the URL request is made: 80 Request.ApplicationPathThe virtual path to the root directory containing the page requested by the browser: /Tutorials Request.FilePathThe virtual path to the page requested by the browser: /Tutorials/ASPNET02/aspnet0 2.aspx

REQUEST OBJECT- Browser Properties Request.PhysicalApplicationPathThe physical path to the root directory of the page requested by the browser: D:\Tutorials\ Request.PhysicalPathThe physical path to the page requested by the browser: D:\Tutorials\ASPNET 02\aspnet02.aspx

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.

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”) %>

Get IP <% Dim strUserName strUserName=Request.ServerVariables ("REMOTE_ADDR") Response.Write strUserName %> merhaba

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

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 )

HTTP Request Header Create the form: Sample Order First Name: Last Name:

HTTP Request Header Title: <input name=“title” type=radio value=“mr”> Mr. Ms.

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. Ms.

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

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 ( Request.ClientCertificate

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-B Certificate: A string value that contains the entire binary stream from the certificate content. Flags: Provide additional information such as presence of certificate.

REQUEST OBJECT- Client Certificate Request.ClientCertificate (“IssuerC”) Retrieve the country of origin for the Issuer. Request.ClientCertificate (“SubjectO”) Retrieve the organization of the Subject.

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.

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

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.

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.

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.

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

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.

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.

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"

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.

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

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