Using Request Information
In
situation one may want to know about the client browser type and generate
contents accordingly.
Request.Browser
Methods
include: GetClrVersions(), IsBrowser(BrowserType)
Properties
Include: ActiveXControls(Supported or Not), AOL (Client is AOL
Browser), BackgroundSounds(<bgsound> supported or not), Browser
(Browser string), ClrVersion( installed version), Cookies(supported),
Crawler (Browser is a search engine or not), Frames(HTML Frames
Supported or not), IsColor(color or grayscale), IsMobiledevice, JavaApplets(Supported
or not), JavaScript, JScriptVersion, MobieDeviceManifecturer,
MobileDeviceModel, MSDOMVersion, Tables, VBScript, Version,
W3CDomVersion, Win16, Win32.
Pages
and Application context overview:
ASP.NET
provides many objects to examine the request and response information.
Response:
HttpResponse.
BinaryWrite, AppendHeader,
Clear, ClearContents, ClearHeaders, End, Flush,
Redirect (302), TransmitFile( Without buffering), Write(Writes
with buffering), WriteFile (Alternative to Server.Transfer, by sending
Http 302 code and new page url. Similar to Response.Redirect),
WriteSubsitution(Uses
HttpResponseSubsitutionCallback delegate to make replacements in cached output,
alternative is to use Substitution control),
Important
properties include:
Cookies, Buffer (if
true response buffered before response), Cache (expiry time, privacy
policy), Expires (Page expiry time at client end), ExpiresAbsolute(absolute
date and time for expiration), Status and StatusCode(Get and Set Http
Status code).
Request: HttpRequest
MapPath: Converts relative
to absolute path. /About.htm Ã
C:\inetpub\wwwroot\about.htm
SaveAs: save the request
file.
ValidateInput: validate input
for potentially dangerous input from user.
Important
properties of Request:
ApplicationPath: Virtual root path
to app.
AppRelativeCurrentExecutionFilePath: returns relative
path + (~). ~/About.htm
Browser: Examine Browser.
ClientCertificate: Security
certificate if client sent some one.
Cookies: Cookies sent by
browser.
FilePath: virtual path of
the current request.
Files: Files uploaded by
client.
Headers: HttpHeaders
collection
HttpMethod: HttpMethod used
like Get, Post, or Head.
IsAuthenticated: Indicates if the
client is authenticated.
IsLocal: If client is from
local network.
IsSecureConnection: True if connection
uses HTTPS.
LogonUserIdentity: WindowsIdentity
that represents the current user.
Params: combination of
QueryString, Form, ServerVariables, and Cookies.
Path: Virtual path of
the current request.
PhysicalApplicationPath: Physical path of
the root directory.
PhysicalPath: Physical path of
the current request.
QueryString: Key/Value
collection of query.
RawURL
and URL:
URL of the current request.
TotalBytes: Length of
request.
URLRefer: URL of the page
from which the user is being redirected to this page.
User
Agent:
User agent string i.e. “Internet Explorer” etc.
UserHostAddress: Client’s IP.
UserHostName: DNS of the remote
client.
UserLanguages: Sorted string
array of languages (Arabic, English, German)
Server: HttpServerUtil
à for processing of
URLs, Path, and HTML.
ClearError(): Clears the last
error:
GetLastError(): return previous
exception.
HtmlDecode(): Removes Html
markups from string.
HtmlEncode(): To Display a page
and convert “<” to “<”
MapPath(): Return physical
path from virtual path.
Transfer(): Stops processing
the current page and starts processing of next page.
URLDecode(): Decodes a string
contained in URL. Client à Server
URLEncode(): Encodes a string
contained in URL. Server à Client
URLPathEncode(): Encodes path
portion of the string.
URLTokenDecode(): Decodes a URL
string token to its equivalent byte array using 64 base.
URLTokenEncode(): Encodes a byte
array to URL for better HTTP Transmission.
Context: HttpContext
It
provides access to many objects that are redundant like Cache, Request,
Response, Server and Session. Some unique methods include:
AddError(): Adds an error
that can be retrieved by Server.GetLastError().
ClearError(): Equivalent to
Server.ClearError().
RewritePath(): Actually
requested path can differ from the internal path. Used especially when
cookieless session is used to remove session information from the path.
Important
Properties include:
AllErrors: Collection of
unhandled exceptions on the page.
IsCustomErrorEnabled: True if custom
errors are enabled.
IsDebuggingEnabled: True if Debugging
is enabled.
Timestamp: Timestamp for
Http request.
Accessing
Web Page Headers:
HTML
Page header contains information like stylesheet to use, Page Title,
and Metadata.
Title
may be required to be modified for search result pages so that when adding to
favorites the criteria also being appended to Page Title.