ASP'NET - PowerPoint PPT Presentation

1 / 60
About This Presentation
Title:

ASP'NET

Description:

DHTML is a browser phenomenon, using JavaScript to manipulate the properties and ... Under ASP.NET these same style settings can take place, in this case through ... – PowerPoint PPT presentation

Number of Views:103
Avg rating:3.0/5.0
Slides: 61
Provided by: Ege2
Category:
Tags: asp | net | dhtml

less

Transcript and Presenter's Notes

Title: ASP'NET


1
ASP.NET
  • Dynamic Styles
  • Response and Request Objects

2
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

3
Dynamic Styles
  • ltSCRIPT language"javascript"gt
  • 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"lt/SCRIPTgtltinput id"BROWSERButton"
    type"button" value"Click Me" onClick"Format()
    style"background-colorsteelblue
    colorFFFFFF font-familyarial font-size10pt
    width100 cursorhand"gt

4
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

5
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 users 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)

6
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

7
RESPONSE OBJECT- Properties/Methods

8
RESPONSE OBJECT Write (ASP)
  • Writes information directly to the HTTP response
    body.
  • lt
  • Response.Write lttable border1gt
  • Response.Write lttrgt
  • Response.Write lttdgt
  • Response.Write Hello
  • Response.Write lt/tdgt
  • Response.Write lt/trgt
  • Response.Write lt/tablegt
  • gt

9
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.
  • ltSCRIPT runat"server"gtSub ProcessThis (Src As
    Object, Args As EventArgs)  Response.Write("Start
    of ProcessThis" "ltbrgt")  ...  ...  Response.
    Write("End of ProcessThis" "ltbrgt")  ProcessThat
    End Sub

10
RESPONSE OBJECT Write (.NET)
Sub ProcessThat  Response.Write("Start of
ProcessThat" "ltbrgt")  Dim VarA
"Howdy"  ...  ...  Response.Write("Value of
VarA " VarA "ltbrgt")  Response.Write("End
of ProcessThat" "ltbrgt")End Sub lt/SCRIPTgt

11
RESPONSE OBJECT Write (.NET)
ltaspButton Text"Trace" OnClick"ProcessThis"
runat"server" /gt Result Start of
ProcessThisEnd of ProcessThisStart of
ProcessThatValue of VarA HowdyEnd of
ProcessThat

12
RESPONSE OBJECT - Redirect
  • Redirects the clients 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.

13
Response.Redirect (ASP)
  • lt Response.Redirect "http//www.mis.boun.edu.tr"
    gt
  • ltHTMLgt
  • ltBODYgt
  • xx
  • lt/BODYgt
  • lt/HTMLgt

14
Response.Redirect (.NET)
  • ltSCRIPT runat"server"gtSub GoBack (Src As
    Object, Args As EventArgs)  Response.Redirect("as
    pnet02-06.aspx")End Sublt/SCRIPTgtltaspButton
    Text"Go Back" OnClick"GoBack" runat"server" /gt

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

16
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
  • lt Response.Buffer True gt

17
RESPONSE OBJECT - Clear
  • Empties the current contents of the Response
    buffer.
  • It does so without sending any of the buffered
    response to the client.

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

19
Response.Buffer/Clear/End
  • lt Response.Buffer True gt
  • ltHTMLgt ltBODYgt
  • lt
  • Dim err
  • err 1
  • If Err ltgt 0 Then
  • Response.Clear
  • Response.Write "Error Created"
  • Response.End
  • End If
  • gt

20
Example Get System Time (ASP)
  • lt LANGUAGEVBSCRIPT gt
  • lthtmlgt ltbodygt
  • lt If Minute(Now) lt 30 Then gt
  • Before Half
  • lt Else gt
  • After Half
  • lt End If gt
  • of
  • lt response.write (Hour(Now)) gt
  • lt/bodygt lt/htmlgt
  • Screen
  • After half of 9
  • Source
  • lthtmlgt ltbodygt
  • After Half
  • of
  • 9
  • lt/bodygt lt/htmlgt

21
Example System Time
  • lt whennow()
  • twoweekslaterdateadd("w",2,when)
  • monthlaterdateadd("m",1,when)
  • sixminuteslaterdateadd("n",6,when)
  • sixhourslaterdateadd("h",6,when)
  • response.write "Now ltbgt" when "lt/bgtltbrgt"
  • response.write "1 month from Now ltbgt"
    monthlater "lt/bgtltbrgt"
  • response.write "2 weeks from Now ltbgt"
    twoweekslater "lt/bgtltbrgt" gt six minutes from
    now ltbgt
  • ltsixminuteslatergt lt/bgtltbrgt six hours from now
    ltbgt
  • ltsixhourslatergt lt/bgtltbrgt

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

23
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

24
REQUEST OBJECT- ServerVariables
Contain several predefined environment variables
in the context of the clients specific HTTP
request of the web server.

25
REQUEST OBJECT- ServerVariables
ltSCRIPT runat"server"gtSub Page_Load  Browser.
Text Request.Browser.Browser  BrowserVersion.Te
xt Request.Browser.Version  BrowserPlatform.Tex
t Request.Browser.PlatformEnd Sub lt/SCRIPTgt

26
REQUEST OBJECT- ServerVariables
lthtmlgtltbodygtlth3gtProperties of your request for
this pagelt/h3gtltbgtBrowser Type lt/bgtltaspLabel
id"Browser" runat"server"/gtltbrgtltbgtBrowser
Version lt/bgtltaspLabel id"BrowserVersion"
runat"server"/gtltbrgtltbgtBrowser Platform
lt/bgtltaspLabel id"BrowserPlatform"
runat"server"/gtltbrgt lt/bodygtlt/htmlgt

27
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

28
REQUEST OBJECT- Browser Properties

29
REQUEST OBJECT- Browser Properties

30
REQUEST OBJECT- Browser Properties

31
REQUEST OBJECT- Browser Properties

32
REQUEST OBJECT- Browser Properties

33
REQUEST OBJECT- Browser Properties

34
REQUEST OBJECT- Browser Properties

35
REQUEST OBJECT- Browser Properties

36
REQUEST OBJECT- Browser Properties

37
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 servers TCP/IP
  • HTTPS ON if the clients request is using SSL.
  • ALL_HTTP One long string containing al the HTTP
    headers send by the clients browser.

38
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
    clients HTTP request is sent.
  • lt
  • Dim strUserName
  • strUserNameRequest.ServerVariables(LOGON_USER)
  • gt

39
Get IP
  • ltHTMLgt ltBODYgt
  • lt Dim strUserName strUserNameRequest.ServerVaria
    bles
  • ("REMOTE_ADDR")
  • Response.Write strUserName
  • gt
  • merhaba
  • lt/BODYgt lt/HTMLgt

40
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

41
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 ltINPUTgt)

42
HTTP Request Header
  • Create the form
  • lthtmlgt ltbodygt lth2gt Sample Order lt/h2gt
  • ltform methodpost actionresponse.aspgt
  • ltpgt First Name ltinput name fname size48gt
  • ltpgt Last Name ltinput name lname size48gt

43
HTTP Request Header
  • ltpgt Title ltinput nametitle typeradio
  • valuemrgt Mr.
  • ltinput nametitle typeradio valuemsgt Ms.
  • ltpgt ltinput typesubmitgt ltinput typeresetgt
  • lt/formgt lt/bodygt lt/htmlgt

44
Response.asp
  • You should use the Form collection of the
    Request object to manipulate information
  • lt title request.form(title)
  • lastname request.form(lname)
  • If title mr Then gt
  • Mr. lt lastname gt
  • lt ElseIf title ms Then gt
  • Ms. lt lastname gt
  • lt Else gt
  • lt request.form (fname) lastname gt
  • lt End If gt

45
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

46
REQUEST OBJECT-Client Certificate
  • Provides access to the certification fields of
    the clients digital certificate.
  • Client certificates are sent to the web server
    when a clients browser supports the Secure
    Sockets Layer and that browser is connected to a
    web server running the SSL (https//).
  • Request.ClientCertificate

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

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

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

50
Session Tracking
  • Session tracking ways
  • Use of input form elements of type hidden and
    sending them to the form handler on the Web
    server.
  • Use of HttpSessionState object
  • Cookies

51
Cookies
  • Cookie Small pieces of information stored by the
    web server on the web clients 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.

52
Cookies
  • Domain Returns a String containing the cookies
    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 cookies
    name.

53
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 cookies
    value.

54
Cookies
  • Send Cookie
  • Response.Cookies("Cust").Name"BE"
  • Response.Cookies("Cust").Expirestime.AddDays(10)
  • Get Cookie
  • Request.Cookies("Cust")
  • Delete Cookie
  • Response.Cookies("Cust").Expires Date 365
  • ' Deleted by setting expiration date to a past
    date

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

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

57
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"

58
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
    objects keys.

59
HttpSessionState Properties
  • SessionID Returns the sessions 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

60
HttpSessionState Properties
  • SessionID Returns the sessions unique ID.
  • Session.
  • Timeout Specifies the maximum number of minutes
    during which a session can be inactive before the
    session expires.
  • Session.Timeout
Write a Comment
User Comments (0)
About PowerShow.com