作为web开发利器,firebug,fillder实乃恩人般的神器。但是它们揭示的是服务器-浏览器之间的巨细事宜,要想了解服务器端的一些细节,还少不了要去F5,F10或者写watch或者各种log。asp.net 其实有自带的trace功能,但是很少有见到一些书籍去介绍或有人去介绍使用经验。话不多说,让我们来启用trace功能以及看它能给出那些关键数据,然后你再考虑下那些场景适合使用此功能。我认为此功能当产品在测试服务器上跑时,特别有用。
一,启用
在<system.web>节点下加如下配置
<trace enabled="true" requestLimit="40" pageOutput="true" localOnly="false" />
二,结果,可以访问url,当前页面在正常页面下端输出trace信息;或者在url后面加?trace.axd,后面一种方式可以在一个窗口查看多个url的trace信息。最终trace保镖如下:
请求详细信息
|
会话 ID: |
c4v1bnbb1ez0vfn34x1a4k45 |
请求类型: |
GET |
请求的时间: |
2012/4/7 23:31:49 |
状态代码: |
200 |
请求编码: |
Unicode (UTF-8) |
响应编码: |
Unicode (UTF-8) |
跟踪信息
|
类别 | 消息 | From First(s) | From Last(s) |
aspx.page |
Begin PreInit |
|
|
aspx.page |
End PreInit |
0.00919911480001343 |
0.009199 |
aspx.page |
Begin Init |
0.0355832640526067 |
0.026384 |
aspx.page |
End Init |
0.0357095911270594 |
0.000126 |
aspx.page |
Begin InitComplete |
0.053047128534384 |
0.017338 |
aspx.page |
End InitComplete |
0.0531000493358439 |
0.000053 |
aspx.page |
Begin PreLoad |
0.0531165515212454 |
0.000017 |
aspx.page |
End PreLoad |
0.053132484665771 |
0.000016 |
aspx.page |
Begin Load |
0.0531489868511725 |
0.000017 |
aspx.page |
End Load |
0.0533157158278151 |
0.000167 |
aspx.page |
Begin LoadComplete |
0.0533441678716107 |
0.000028 |
aspx.page |
End LoadComplete |
0.0533612390978881 |
0.000017 |
aspx.page |
Begin PreRender |
0.0533771722424137 |
0.000016 |
aspx.page |
End PreRender |
0.0534630974146766 |
0.000086 |
aspx.page |
Begin PreRenderComplete |
0.0550911233606644 |
0.001628 |
aspx.page |
End PreRenderComplete |
0.0551696510015404 |
0.000079 |
aspx.page |
Begin SaveState |
0.118867517610393 |
0.063698 |
aspx.page |
End SaveState |
0.136335365378301 |
0.017468 |
aspx.page |
Begin SaveStateComplete |
0.136397959874652 |
0.000063 |
aspx.page |
End SaveStateComplete |
0.136416169182681 |
0.000018 |
aspx.page |
Begin Render |
0.136432102327206 |
0.000016 |
aspx.page |
End Render |
0.152798286959347 |
0.016366 |
控件树
|
控件 UniqueID | 类型 | 呈现大小字节数(包括子级) | ViewState 大小字节数(不包括子级) | ControlState 大小字节(不包括子级) |
__Page |
ASP.default_aspx |
667 |
0 |
0 |
ctl02 |
System.Web.UI.LiteralControl |
174 |
0 |
0 |
ctl00 |
System.Web.UI.HtmlControls.HtmlHead |
157 |
0 |
0 |
ctl01 |
System.Web.UI.HtmlControls.HtmlTitle |
19 |
0 |
0 |
ctl03 |
System.Web.UI.LiteralControl |
125 |
0 |
0 |
ctl04 |
System.Web.UI.LiteralControl |
14 |
0 |
0 |
form1 |
System.Web.UI.HtmlControls.HtmlForm |
302 |
0 |
0 |
ctl05 |
System.Web.UI.LiteralControl |
90 |
0 |
0 |
ctl06 |
System.Web.UI.LiteralControl |
20 |
0 |
0 |
标头集合
|
名称 | 值 |
Connection |
keep-alive |
Accept |
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 |
Accept-Encoding |
gzip, deflate |
Accept-Language |
zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 |
Host |
localhost:1142 |
User-Agent |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0 |
响应标头集合
|
名称 | 值 |
X-AspNet-Version |
2.0.50727 |
Cache-Control |
private |
Content-Type |
text/html |
服务器变量
|
名称 | 值 |
ALL_HTTP |
HTTP_CONNECTION:keep-alive HTTP_ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 HTTP_HOST:localhost:1142 HTTP_USER_AGENT:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0 |
ALL_RAW |
Connection: keep-alive Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 Host: localhost:1142 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0 |
APPL_MD_PATH |
|
APPL_PHYSICAL_PATH |
F:\demos\2012\cachetest\ |
AUTH_TYPE |
|
AUTH_USER |
|
AUTH_PASSWORD |
|
LOGON_USER |
wusong-PC\wusong |
REMOTE_USER |
|
CERT_COOKIE |
|
CERT_FLAGS |
|
CERT_ISSUER |
|
CERT_KEYSIZE |
|
CERT_SECRETKEYSIZE |
|
CERT_SERIALNUMBER |
|
CERT_SERVER_ISSUER |
|
CERT_SERVER_SUBJECT |
|
CERT_SUBJECT |
|
CONTENT_LENGTH |
0 |
CONTENT_TYPE |
|
GATEWAY_INTERFACE |
|
HTTPS |
|
HTTPS_KEYSIZE |
|
HTTPS_SECRETKEYSIZE |
|
HTTPS_SERVER_ISSUER |
|
HTTPS_SERVER_SUBJECT |
|
INSTANCE_ID |
|
INSTANCE_META_PATH |
|
LOCAL_ADDR |
127.0.0.1 |
PATH_INFO |
/cachetest/Default.aspx |
PATH_TRANSLATED |
F:\demos\2012\cachetest\Default.aspx |
QUERY_STRING |
|
REMOTE_ADDR |
127.0.0.1 |
REMOTE_HOST |
127.0.0.1 |
REMOTE_PORT |
|
REQUEST_METHOD |
GET |
SCRIPT_NAME |
/cachetest/Default.aspx |
SERVER_NAME |
localhost |
SERVER_PORT |
1142 |
SERVER_PORT_SECURE |
0 |
SERVER_PROTOCOL |
HTTP/1.1 |
SERVER_SOFTWARE |
|
URL |
/cachetest/Default.aspx |
HTTP_CONNECTION |
keep-alive |
HTTP_ACCEPT |
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 |
HTTP_ACCEPT_ENCODING |
gzip, deflate |
HTTP_ACCEPT_LANGUAGE |
zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 |
HTTP_HOST |
localhost:1142 |
HTTP_USER_AGENT |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0 |
更多细节请看MSDN:ASP.NET 跟踪