人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

August 14, 2006

ASP.net trace and debug

Filed under: ASP.NET

这两个功能的开关都有两个级别: Application级(在web.config中设置),页面级(在<@Page>中设置)
以Page中的设定为准.

此外.net 2.0 的machine.cofig中还有一个机器级的设定:
<system.web>
<deployment retail=”false” />
</system.web>
一旦retail=”true”所有的Trace, debug设定统统无效.
参考MSDN How to: Precompile ASP.NET Web Sites for Deployment

正式服务器一定不要用debug, trace
http://blogs.msdn.com/tess/archive/2006/04/13/575364.aspx
http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx

>>有关 Trace:
1. 如果web.config中的Trace设定为false,就不能使用Trace.axd来
查看Trace信息.

2. TarceMode=”SortByCategory”设置Trace信息的显示顺序.

3. 条件输出
if(Trace.IsEnabled)
Trace.Write

4. 完全用代码控制:
void Page_Load (object sender, EventArgs e)
{
Trace.TraceFinished +=new TraceContextEventHandler (OnTraceFinished);
}

void OnTraceFinished (object sender, TraceContextEventArgs e)
{
foreach (TraceContextRecord record in e.TraceRecords)
{
Response.Write (String.Format (”{0}: {1}<br>”,record.Category, record.Message));
}
}
在vs2005中,可以使用下边的配置在output window中显示trace信息.
<configuration>
<system.web>
<trace enabled=”true” writeToDiagnosticsTrace=”true” />
</system.web>
</configuration>

参考 Power Programming Tips for ASP.NET 2.0 一文

>>有关Debug
1. 和<customError mode=”">联合使用,根据error code跳转到不同页
2. 在Page.Error中进行错误处理
Page_Error
{
Server.GetLastError().ToString(); //显示call stack
}

3. 常见错误
IIS 状态代码(http://support.microsoft.com/?id=318380)

500 内部服务器错误
403 No access
404 Not found

参考
ASP.NET 2.0 监视你的应用
http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/episode.aspx?newsID=1242387

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/08/14/aspnet-trace-and-debug/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham