ASP.NET 提供了幾個系統物件,可以用來存取許多相當有用的資訊,例如取得使用者IP,瀏覽器種類等等。 這類物件必須透過 Page 物件的屬性取得,包含:

  • Request :這個物件包含目前 HTTP 要求的相關資訊。
  • Response :這個物件包含回應資訊,允許您將資訊,透過 HTTP 回應給用戶端。
  • Context :這個物件提供網頁執行內容的相關資訊。
  • Browser :取得或設定關於用戶端瀏覽器的資訊。
  • Server :這個屬性提供常用的 HtmlEncodeMapPath 方法。
  • Application :取得目前 Web 要求的 HttpApplicationState 物件。
  • Session :這個屬性提供目前要求的工作階段(Session)資訊。
  • Trace :追蹤並顯示關於 Web 要求的執行詳細資料。

Response

Response 方法

 方法說明
 AddHeaderAdds an HTTP header to the response stream.
 AppendCookie 
 AppendHeader 
 AppendToLog 
 BinaryWriteWrites binary characters to the HTTP response.
 Clear 
 ClearContent 
 ClearHeaders 
 EndCompletes the response
 Flush強迫送出目前存放在緩衝區的資料,並清除目前存放在緩衝區的資料
 Redirect 
 SetCookie 
 TransmitFile 
 WriteWrites a text string to the HTTP response.
 WriteFileWrites a file to the HTTP response with buffering.
 WriteSubstitutionThis allow you to dynamically update that cached output.
Response.Redirect與Server.Transfer差別

請參考:http://www.dotblogs.com.tw/jimmyyu/archive/2009/11/10/11503.aspx

Response 屬性

屬性資料說明
BufferTrueIf True, the response is buffered before sending it back to the user. <br> If False, the response is sent back to the user in chunks.
CacheSystem.Web.HttpCachePolicy 
CookiesSystem.Web.HttpCookieCollection 
Expires0 
ExpiresAbsolute0001/1/1 上午 12:00:00 
Filter  
IsClientConnectedTrue取得瀏覽端是否還處於連線狀態
Status200 OK 
StatusCode200 

Request

Request 方法

 方法說明
 MapPath將用戶端目前要求之 URL 的虛擬路徑對應至伺服器上的實體路徑。
 SaveAsSaves the request to a file.
 ValidateInput是否對透過 Cookies、Form 和 QueryString 屬性執行潛在危險之驗證

Request 屬性

屬性資料說明                                                                                                                                                                                                                                                    
ApplicationPath/                                                                                                                                                                                                                                                     
AppRelativeCurrentExecutionFilePath~/C08_Programming_the_Web_Application/WebForm2.aspx取得應用程式的虛擬路徑                                                                                                                                                                                                                                                    
BrowserSystem.Web.Mobile.MobileCapabilities取得用戶端瀏覽器的資訊。                                                                                                                                                                                                                                                    
ClientCertificateSystem.Web.HttpClientCertificate                                                                                                                                                                                                                                                     
CookiesSystem.Web.HttpCookieCollection取得用戶端送出的 Cookie 的集合。                                                                                                                                                                                                                                                    
FilePath/C08_Programming_the_Web_Application/WebForm2.aspx目前要求的虛擬路徑。                                                                                                                                                                                                                                                    
FilesSystem.Web.HttpFileCollection                                                                                                                                                                                                                                                     
Filter                                                                                                                                                                                                                                                      
HeadersCache-Control=no-cache&Connection=Keep-Alive&Content-Length=429&Content-Type=application%2fx-www-form-urlencoded&Accept=text%2fhtml%2c+application%2fxhtml%2bxml%2c+*%2f*&Accept-Encoding=gzip%2c+deflate&Accept-Language=zh-TW&Cookie=ASP.NET_SessionId%3drzsgttim0kc0sagrgm4l0nvi&Host=localhost%3a60755&Referer=http%3a%2f%2flocalhost%3a60755%2fC08_Programming_the_Web_Application%2fWebForm2.aspx&User-Agent=Mozilla%2f5.0+(compatible%3b+MSIE+9.0%3b+Windows+NT+6.1%3b+WOW64%3b+Trident%2f5.0%3b+NP06)                                                                                                                                                                                                                                                     
HttpMethodPOST                                                                                                                                                                                                                                                     
IsAuthenticatedTrue                                                                                                                                                                                                                                                     
IsLocalTrue                                                                                                                                                                                                                                                     
IsSecureConnectionFalse                                                                                                                                                                                                                                                     
LogonUserIdentitySystem.Security.Principal.WindowsIdentity                                                                                                                                                                                                                                                     
Params NameValue說明<br><br>__EVENTVALIDATION/wEWEAKy+bbNBgKf7OeoAgLw/96vBwKu+JOJCwKKkYyiBAKx6YT7DQKiotE5AveptakBAvGhyJwOApnC0/UMAu7CqaMOAvTX2fcMAuPv3sAFAqfzke4GAubYlJQIArur8Z0KILtAbiO7t33VgM69Ar+iv7lOgtaa23CBQcz9pJqpbQg= <br>__VIEWSTATE/wEPDwUKLTc4NzI2MDczNmQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFDGNiSW5jbHVkZVVybAUKY2JTaG93VGV4dGOWKpza/lXYoFZ5KMT+pWaUtalW0DTOMQ0iHhxiDaw+ <br>ALL_HTTPHTTP_CACHE_CONTROL:no-cache <br>HTTP_CONNECTION:Keep-Alive <br>HTTP_CONTENT_LENGTH:420 <br>HTTP_CONTENT_TYPE:application/x-www-form-urlencoded <br>HTTP_ACCEPT:text/html, application/xhtml+xml, */* <br>HTTP_ACCEPT_ENCODING:gzip, deflate <br>HTTP_ACCEPT_LANGUAGE:zh-TW <br>HTTP_COOKIE:ASP.NET_SessionId=ent0y41l14cd4yizcegchl0o <br>HTTP_HOST:localhost:60755 <br>HTTP_REFERER:http://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx <br>HTTP_USER_AGENT:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06) <br>ALL_RAWCache-Control: no-cache <br>Connection: Keep-Alive <br>Content-Length: 420 <br>Content-Type: application/x-www-form-urlencoded <br>Accept: text/html, application/xhtml+xml, */* <br>Accept-Encoding: gzip, deflate <br>Accept-Language: zh-TW <br>Cookie: ASP.NET_SessionId=ent0y41l14cd4yizcegchl0o <br>Host: localhost:60755 <br>Referer: http://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx <br>User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06) <br>APPL_MD_PATH  <br>APPL_PHYSICAL_PATHD:\myMCTS\VitoPractice\70-528\Practice70515\ <br>ASP.NET_SessionIdent0y41l14cd4yizcegchl0o <br>AUTH_PASSWORD  <br>AUTH_TYPENTLM <br>AUTH_USERVITO-2011W7\Administrator <br>btnParamsRequest’s Params <br>cbShowTexton <br>CERT_COOKIE  <br>CERT_FLAGS  <br>CERT_ISSUER  <br>CERT_KEYSIZE  <br>CERT_SECRETKEYSIZE  <br>CERT_SERIALNUMBER  <br>CERT_SERVER_ISSUER  <br>CERT_SERVER_SUBJECT  <br>CERT_SUBJECT  <br>CONTENT_LENGTH420 <br>CONTENT_TYPEapplication/x-www-form-urlencoded <br>GATEWAY_INTERFACE  <br>HTTP_ACCEPTtext/html, application/xhtml+xml, */* <br>HTTP_ACCEPT_ENCODINGgzip, deflate <br>HTTP_ACCEPT_LANGUAGEzh-TW <br>HTTP_CACHE_CONTROLno-cache <br>HTTP_CONNECTIONKeep-Alive <br>HTTP_CONTENT_LENGTH420 <br>HTTP_CONTENT_TYPEapplication/x-www-form-urlencoded <br>HTTP_COOKIEASP.NET_SessionId=ent0y41l14cd4yizcegchl0o <br>HTTP_HOSTlocalhost:60755 <br>HTTP_REFERERhttp://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx <br>HTTP_USER_AGENTMozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06) <br>HTTPS  <br>HTTPS_KEYSIZE  <br>HTTPS_SECRETKEYSIZE  <br>HTTPS_SERVER_ISSUER  <br>HTTPS_SERVER_SUBJECT  <br>INSTANCE_ID  <br>INSTANCE_META_PATH  <br>LOCAL_ADDR::1 <br>LOGON_USERVITO-2011W7\Administrator <br>PATH_INFO/C08_Programming_the_Web_Application/WebForm2.aspx <br>PATH_TRANSLATEDD:\myMCTS\VitoPractice\70-528\Practice70515\C08_Programming_the_Web_Application\WebForm2.aspx <br>QUERY_STRING  <br>REMOTE_ADDR::1 <br>REMOTE_HOST::1 <br>REMOTE_PORT  <br>REMOTE_USERVITO-2011W7\Administrator <br>REQUEST_METHODPOST <br>SCRIPT_NAME/C08_Programming_the_Web_Application/WebForm2.aspx <br>SERVER_NAMElocalhost <br>SERVER_PORT60755 <br>SERVER_PORT_SECURE0 <br>SERVER_PROTOCOLHTTP/1.1 <br>SERVER_SOFTWARE  <br>URL/C08_Programming_the_Web_Application/WebForm2.aspx  取得 QueryString、Form、Cookies 和 ServerVariables 項目的組合集合。
Path/C08_Programming_the_Web_Application/WebForm2.aspx取得目前要求的虛擬路徑。                                                                                                                                                                                                                                                    
PathInfo                                                                                                                                                                                                                                                      
PhysicalApplicationPathD:\myMCTS\VitoPractice\70-528\Practice70515\取得目前正在執行的伺服器應用程式的根目錄之實體檔案系統路徑。                                                                                                                                                                                                                                                    
PhysicalPathD:\myMCTS\VitoPractice\70-528\Practice70515\C08_Programming_the_Web_Application\WebForm2.aspx取得對應到要求的 URL 之實體檔案系統路徑。                                                                                                                                                                                                                                                    
QueryStringUser=vito&Page=2取得 HTTP 查詢字串變數的集合。                                                                                                                                                                                                                                                    
RawUrl/C08_Programming_the_Web_Application/WebForm2.aspx                                                                                                                                                                                                                                                     
ServerVariables NameValue說明<br><br>ALL_HTTPHTTP_CACHE_CONTROL:no-cache <br>HTTP_CONNECTION:Keep-Alive <br>HTTP_CONTENT_LENGTH:438 <br>HTTP_CONTENT_TYPE:application/x-www-form-urlencoded <br>HTTP_ACCEPT:text/html, application/xhtml+xml, */* <br>HTTP_ACCEPT_ENCODING:gzip, deflate <br>HTTP_ACCEPT_LANGUAGE:zh-TW <br>HTTP_COOKIE:ASP.NET_SessionId=ent0y41l14cd4yizcegchl0o <br>HTTP_HOST:localhost:60755 <br>HTTP_REFERER:http://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx <br>HTTP_USER_AGENT:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06) <br>ALL_RAWCache-Control: no-cache <br>Connection: Keep-Alive <br>Content-Length: 438 <br>Content-Type: application/x-www-form-urlencoded <br>Accept: text/html, application/xhtml+xml, */* <br>Accept-Encoding: gzip, deflate <br>Accept-Language: zh-TW <br>Cookie: ASP.NET_SessionId=ent0y41l14cd4yizcegchl0o <br>Host: localhost:60755 <br>Referer: http://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx <br>User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06) <br>APPL_MD_PATH  <br>APPL_PHYSICAL_PATHD:\myMCTS\VitoPractice\70-528\Practice70515\ <br>AUTH_PASSWORD  <br>AUTH_TYPENTLM <br>AUTH_USERVITO-2011W7\Administrator <br>CERT_COOKIE  <br>CERT_FLAGS  <br>CERT_ISSUER  <br>CERT_KEYSIZE  <br>CERT_SECRETKEYSIZE  <br>CERT_SERIALNUMBER  <br>CERT_SERVER_ISSUER  <br>CERT_SERVER_SUBJECT  <br>CERT_SUBJECT  <br>CONTENT_LENGTH438 <br>CONTENT_TYPEapplication/x-www-form-urlencoded <br>GATEWAY_INTERFACE  <br>HTTP_ACCEPTtext/html, application/xhtml+xml, */* <br>HTTP_ACCEPT_ENCODINGgzip, deflate <br>HTTP_ACCEPT_LANGUAGEzh-TW <br>HTTP_CACHE_CONTROLno-cache <br>HTTP_CONNECTIONKeep-Alive <br>HTTP_CONTENT_LENGTH438 <br>HTTP_CONTENT_TYPEapplication/x-www-form-urlencoded <br>HTTP_COOKIEASP.NET_SessionId=ent0y41l14cd4yizcegchl0o <br>HTTP_HOSTlocalhost:60755 <br>HTTP_REFERERhttp://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx <br>HTTP_USER_AGENTMozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06) <br>HTTPS  <br>HTTPS_KEYSIZE  <br>HTTPS_SECRETKEYSIZE  <br>HTTPS_SERVER_ISSUER  <br>HTTPS_SERVER_SUBJECT  <br>INSTANCE_ID  <br>INSTANCE_META_PATH  <br>LOCAL_ADDR::1 <br>LOGON_USERVITO-2011W7\Administrator <br>PATH_INFO/C08_Programming_the_Web_Application/WebForm2.aspx <br>PATH_TRANSLATEDD:\myMCTS\VitoPractice\70-528\Practice70515\C08_Programming_the_Web_Application\WebForm2.aspx <br>QUERY_STRING  <br>REMOTE_ADDR::1 <br>REMOTE_HOST::1 <br>REMOTE_PORT  <br>REMOTE_USERVITO-2011W7\Administrator <br>REQUEST_METHODPOST <br>SCRIPT_NAME/C08_Programming_the_Web_Application/WebForm2.aspx <br>SERVER_NAMElocalhost <br>SERVER_PORT60755 <br>SERVER_PORT_SECURE0 <br>SERVER_PROTOCOLHTTP/1.1 <br>SERVER_SOFTWARE  <br>URL/C08_Programming_the_Web_Application/WebForm2.aspx  取得 Web 伺服器變數的集合。                    
TotalBytes429                                                                                                                                                                                                                                                     
Urlhttp://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx目前要求的 URL 資訊。                                                                                                                                                                                                                                                    
UrlReferrerhttp://localhost:60755/C08_Programming_the_Web_Application/WebForm2.aspx前一個要求之 UR 資訊。L                                                                                                                                                                                                                                                    
UserAgentMozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; NP06)取得用戶端瀏覽器的字串資訊                                                                                                                                                                                                                                                    
UserHostAddress::1                                                                                                                                                                                                                                                     
UserHostName::1                                                                                                                                                                                                                                                     
UserLanguagesSystem.String[]                                                                                                                                                                                                                                                     

Server

Server 方法

Server 屬性

屬性資料說明
MachineNameVITO-2011W7 
ScriptTimeout30000000 

Context 物件

The Page.Context property is an HttpContext object that provides access to a variety of objects related to the HTTP request and response. Many of these objects are redundant, providing access to Page members including Cache, Request, Response, Server, and Session. However, the Context object includes several unique methods:

Context 方法

 方法說明
 AddError 
 ClearError 
 RewritePath使用指定的路徑重寫 URL。

Context 屬性

屬性資料說明
AllErrors  
IsCustomErrorEnabledTrue 
IsDebuggingEnabledTrue 
Timestamp2012/10/2 上午 11:52:29 

Browser

取得瀏覽器相關的資訊

Request.Browser 的方法

 方法說明
 AddBrowser 
 GetClrVersions傳回安裝在用戶端的所有 .NET Framework CLR 版本。
 IsBrowser用戶端瀏覽器是否與指定瀏覽器相同。

Request.Browser 的屬性

屬性資料說明
ActiveXControlsTrue是否支援 ActiveX
AOLFalse是否是 AOL (America Online) 瀏覽器
BackgroundSoundsTrue是否支援 <bgsounds>標籤
BrowserIE 
BrowsersSystem.Collections.ArrayList 
ClrVersion0.0取得用戶端安裝的 .NET Framework 版本
CookiesTrue是否支援 Cookie
CrawlerFalse是否為 Web Crawler 搜尋引擎
FramesTrue是否支援 HTML 框架
IsColorTrue 
IsMobileDeviceFalse 
Item 
JavaAppletsTrue 
JavaScriptTrue 
JScriptVersion5.6 
MobileDeviceManufacturerUnknown 
MobileDeviceModelUnknown 
MSDomVersion9.0 
NumberOfSoftkeys0 
PlatformWinNT 
TablesTrue 
VBScriptTrue 
Version9.0取得瀏覽器完整版本號碼
W3CDomVersion1.0 
Win16False 
Win32True 

Page.Header

Page.Header 方法

 方法說明
 ApplyStyleSheetSkin 
 GetRouteUrl 

Page.Header 屬性

| 屬性 | 說明 | 資料 | | — | — | — | | Style | 取得樣式表屬性集合 | System.Web.UI.CssStyleCollection | | StyleSheet | 設定網頁樣式 | c# Style bodystyle = new Style();<br>bodystyle.ForeColor = System.Drawing.Color.Blue;<br>bodystyle.BackColor = System.Drawing.Color.LightCyan;<br>Page.Header.StyleSheet.CreateStyleRule(bodystyle,null,"body");<br> <br> <br>以上程式碼,將在<head>區塊裡,產生以下樣式<br> <br>```xml


| | [Title](http://msdn.microsoft.com/zh-tw/library/system.web.ui.htmlcontrols.htmlhead.title.aspx) | 設定網頁標題 |c# Page.Header.Title = “Current tim: “ + DateTime.Now;
``` | | ViewStateMode | | Inherit | | Visible | | True |