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

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 阿昆

[分享]真正的分页存储过程,借鉴了CSDN上众多力量,除BUG版,分享给大家 CommunityServer页面间关系 CommunityServer研习心得 CommunityServer皮肤主题的更换 CommunityServer实例分析 CommunityServer布局 - 阿昆 - 博客园 Community Server系列之六:CS2中的关键词及数据结构 Community Server系列之八:CS2中的CSContext Community Server系列之四:Ajax在CS2.0中的应用1 Community Server配置对网址中的www信息处理功能分析 Community Server架构:博客业务详细分析 如何在 Microsoft Visual Studio 2005 中直接Debug Community Server 2.0 的代码 与 Visual Studio 2005 Web Application Projects Community Server2.0专注细节一 邮件提醒按钮实现(上) Community Server专题附录一: 什么是Threads & Processes Community Server专题九:MemberRole之Profile Community Server专题八:MemberRole之Membership深入篇 Community Server专题八:MemberRole之Membership Community Server专题七: Job & Timer Community Server专题六:Delegates & Events - 阿昆
Community Server系列之七:快速找到需要修改的文件[技巧]
阿昆 · 2006-06-02 · via 博客园 - 阿昆
  

       CS中的模板几乎遍布整个应用,当我们利用SDK做二次开发的时候,我们需要很长的熟悉过程,而这个过程大部分时间被烦躁的检索所占据,检索模板、检索类文件,检索类文件我们可以使用类视图快速定位到类所在的文件。然而确定需要修改的模板或需要修改的类却不是那么方便的事情。CS在这里为我们做了一些工作,但并不是特别方便,按照下面的方法即可直观的找到需要修改的文件。

       CS中,如果是调试项目,在生成的HTML代码里会嵌入页面所使用的模板的类名及模板文件路径,但它是以HTML注释的方式体现出来的,我们要确定某个模块的信息还需要查看源文件并繁琐的检索,这里我们只需要稍微改造一下便能让这些注释更直观一眼就可以快速了解模块的相关信息。

让我们打开\src\Controls\BaseClasses\TemplatedWebControl.cs\src\Controls\BaseClasses\SkinnedWebControl.cs这两个文件,这两个类是系统模板控件的基类,它们都有这样一个方法:

[System.Diagnostics.Conditional("DEBUG")]
        
protected void SourceMarker(bool isStart, HtmlTextWriter writer)
        {
           
            
if(isStart)
            {
                writer.WriteLine("<!-- Start: {0} -->", 
this.GetType());
                
                
if(System.IO.File.Exists(HttpContext.Current.Server.MapPath(this.SkinPath)))
                    writer.WriteLine("<!-- Skin Path: {0} -->", 
this.SkinPath);
                
else if(SkinTemplate != null)
                    writer.WriteLine("<!-- Inline Skin: {0} -->", 
true);
                
else
                    writer.WriteLine("<!-- Skin Path: {0} -->", 
this.DefaultSkinPath);

            }

else
                writer.WriteLine("<!-- End: {0} -->", 
this.GetType());
        }


这个方法的目的即是,在Debug编译环境下,控件输出的时候记录控件所属于的类名和控件所使用的skin路径,方便客户端通过HTML代码找到相应的代码进行修改,然而这里使用的是HTML注释,我们在查找的时候很不方便,那么我们把它转换成HTML隐藏的标签并在需要的时候让其制动显示在浏览器上不是更方便吗,这就进行改造,修改此方法如下:

SourceMarker
[System.Diagnostics.Conditional("DEBUG")]
        
protected void SourceMarker(bool isStart, HtmlTextWriter writer)
        
{
           
            
//Edit by lf
            if(isStart)
            
{
                writer.WriteLine("<span style='display:none;background-color:infobackground;' id='classInfo' name='classInfo'> Start: {0} </span>", 
this.GetType());
                
                
string skinPath = Globals.GetSkinPath() + "/Skins/" + SkinFilename.TrimStart('/');
                
if(System.IO.File.Exists(skinPath))
                    writer.WriteLine("<span style='display:none;background-color:infobackground;' id='skinInfo' name='skinInfo'> Skin Path: {0} </span>", skinPath);
               
else
                    writer.WriteLine("<span style='display:none;background-color:infobackground;' id='skinInfo' name='skinInfo'> Skin Path: {0} </span>", Globals.ApplicationPath + "/Themes/default/Skins/" + SkinFilename.TrimStart('/'));
            }
            
else
                writer.WriteLine("<span style='display:none;background-color:infobackground;' id='classInfo' name='classInfo'> End: {0} </span>", 
this.GetType());
        }


聪明的你一定看出来了,这里其实很简单,只是把相应的HTML注释改为隐藏的span标签,对应的两个类文件都按照这样的方式进行修改即可。
修改了上述两个文件后还需要修改另外一个每页都需要的文件,这里我们选择\src\Controls\Utility\Footer.cs这个文件,因为这个脚标文件在每个页面都用得着,我们可以在这里设置一个开关让其通过点击自动显示和隐藏上面所修改的标签。
Footer这个类的Render方法里把相应的writer.Writer方法改为如下所示样式,这样在Debug的时候就可以点击页脚的SkinInSkinClass三个连接来显示相应的Debug标签了。

Footer
#if DEBUG
                writer.Write("&copy; Copyright 2006 XXXXXX Corporation. All Rights Reserved. <span onclick='showDebugObj(\"skinInfo\")'>Skin</span> <span onclick='showDebugObj(\"inSkinInfo\")'>InSkin</span> <span onclick='showDebugObj(\"classInfo\")'>Class</span>");
                writer.Write(@"<script language='javascript'>
function showDebugObj(n){
    var objs = document.getElementsByName(n);
    if(objs.length == 0) alert('Not Found:' + n);
    for(i=0;i<objs.length;i++){
        if(objs[i].style.display == 'none')
            objs[i].style.display = '';
        else
            objs[i].style.display = 'none';    
    }
}
</script>
");
#else
                 writer.Write("&copy; Copyright 2006 XXXXXX Corporation. All Rights Reserved.");
#endif


通过上面的改造我们可以在页脚看到三个标签:SkinInSkinClass当我们点击这三个标签的时候页面就会显示相应的控件的类名,Skin路径等信息,这在二次开发CS的过程中可以非常快速的定位到想修改的资源,节约大量的检索时间。希望对您有所帮助。