惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - Guxx

一路有你站点开通,特别祝贺 mstIsUsedBy Domino和IIS共存一台服务器的配置 Subversion安装 showModalDialog打开网页和disabled后表单提交的问题。 项目刷新失败,无法从服务器中检索文件夹信息 css在不同的文档类型中的区别 - Guxx - 博客园 A标签伪类的使用方法 不规范的命名对ASP.NET中基于窗体的自定义身份验证的影响 Flash动态载入JPEG图片 在线配色 我曾经做过的网站 DotNetNuke的皮肤研究笔记 解决DotNetNuke3.0.8菜单不能使用中文的方法 IIS应用程序池的设置对dotnetnuke3.0.8运行的影响 让IE窗口填满屏幕,但不是FullScreen. Sps界面定制手记 Asp.Net服务器控件开发心得 如何批量加密存储过程?
ASP.NET的调试方法
Guxx · 2005-10-24 · via 博客园 - Guxx

程序的调试方法,对于编写高质量的程序有着很大关系,用之得当,事半功倍。下面,我就把我对ASP.NET调试技术的了解给大家说说,还希望大家多多指教。

条件编译:
条件编译,是.NET的调试中非常重要的方法之一,它可以根据编译条件来动态生成运行代码。
条件编译是在生成代码时用/define指定的常数,结合代码中的#if  常数....#endif来判断是否生成#if....#endif部分代码。
条件编译常数,可以在项目属性->配置属性->生成->条件编译常数中指定,也可以在命令行中指定。对于一个代码文件来说,你也可以在文件头部分定义,如在.cs文件中,#define DEBUG,也可以#undef  DEBUG取消。我个人觉得,在项目属性中指定灵活性要大一些,因为你可以根据不同的配置设置不同的常数。条件编译常数格式为:DEBUG;TRACE。常数不限于DEBUG和TRACE,你可以指定任何单词。

当我们定义好条件编译常数后,在程序代码中就可以使用了。如我们为了在调试版本中显示一些中间状态信息,而发布版本不需要显示,我们可以这样:
c#

/// <summary>
/// 初始化
/// </summary>

private void Initialize()
{
    
try
    
{
        
int x = 0;
        
int i = 1 / x;
    }

    
catch(Exception e)
    
{
        
#if DEBUG
        Debug.Listeners.Add(
new TextWriterTraceListener(Console.Out));
            //Debug.Listeners.Add(new TextWriterTraceListener("Debug Result.Log");    //写调试信息到文件中。
        Debug.AutoFlush 
= true;
        Debug.WriteLine(e.Message);
        Debug.Close();
        
#endif//DEBUG
        Response.Write(
"初始化" + e.Message) ;
    }

}

 Web窗体代码中的条件编译选项
为了在Web窗体代码中启用条件编译,你需要设置<%@Page Language="C#" Debug="True" %>

Web.Config中的debug
在Web.Config文件是,会有<compilation defaultLanguage="c#" debug="true" />一行,这个功能是确定程序是否要加载调试符号,如果我们要在IDE的调试模式下运行,debug必须为true,但为了提高性能,在发布时我们需要设置debug为false。

暂时写这么多。