﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-阿不</title><link>http://www.cnblogs.com/hjf1223/</link><description>用勤奋寻找未来</description><language>zh-cn</language><lastBuildDate>Fri, 03 Jul 2009 23:24:33 GMT</lastBuildDate><pubDate>Fri, 03 Jul 2009 23:24:33 GMT</pubDate><ttl>60</ttl><item><title>如何动态给BuildManager增加程序集引用</title><link>http://www.cnblogs.com/hjf1223/archive/2009/04/22/BuildManager_multi_bin.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Wed, 22 Apr 2009 01:57:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2009/04/22/BuildManager_multi_bin.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1440992.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2009/04/22/BuildManager_multi_bin.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1440992.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1440992.html</trackback:ping><description><![CDATA[<p>System.Web.Compilation.BulidManager负责站点的动态编译，所有的页面、用户控件、和所有的ASP.NET特殊目录，都会在运行时被BuildManager编译和处理，也包括Bin目录。我们知道在ASP.NET中，所有的页面和控件都包括.ASPX和后台代码文件，除了代码文件在编译时会被静态编译成一个类型外，.ASPX文件在运行时也会被动态编译在一个动态类型中，以便写在.ASPX上的C#代码能够被运行。</p> <p>而在编译时，如果使用到外部类型，是需要引用外部类型的程序集，否则无法编译成功。我们也经常会遇到类型的编译错误：</p> <p><pre>CS0246: The type or namespace name '*******' could not be found (are you missing a using directive or an assembly reference?)</pre>
<p></p>
<p>而解决问题的最好办法就是我们把编译所需的程序集放到Bin目录，这样就可以保证BuildManager编译成功。但是在某些环境中，我们就是不希望将这样的引用程序集放成Bin目录，而通过动态载入的形式载入所需的程序集。</p>
<p>BuildManager的内部很复杂，但是它所提供的接口却非常的有限，都只是查询类型和程序集的接口。因为在BuildManager中管理着系统中最全的类型和程序集，所有动态编译的类型和程序集都可以通过BuildManager的查询接口得到。也就是说，即使你通过Type.GetType接口无法得到的类型，可能你通过BuildManager.GetType就可以得到，前提是在当前的运行时确实存在着这个类型。BuildManager所维护的程序集列表，也比AppDomain维护的列表多得多，在BuildManager里还订阅了AppDomain.CurrentDomain.AssemblyResolve向当前Domain提供所需的程序集。</p>
<p>在BuildManager编译时，它都会把Bin目录的所有程序集按一定的规则拷贝到"%WINDIR%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files"相应的动态目录里，每个程序集单独一个目录，并配上__AssemblyInfo__.ini。</p>
<p>显然，我们让BuildManager在动态编译时动态增加程序集引用，是无法通过AppDomain来加载程序集来实现。必须想办法让程序集能够被添加到BuildManager的引用列表中，并且最好能够做到，不在Bin目录下的程序集，也会被动态拷贝到相应的动态目录里面，实际上要达到的行为是一个站点目录中可能会同时出现多个Bin目录。</p>
<p>通过搜索，我找到这样的答案，在Web.config做如下的配置，即可在一个站点里面设置多个Bin目录，让站点在编译时能找到引用：</p><pre>&lt;runtime&gt;
  &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
    &lt;probing privatePath="WebFileManager/bin" /&gt;
  &lt;/assemblyBinding&gt;
&lt;/runtime&gt;
</pre><pre>全文完</pre><img src ="http://www.cnblogs.com/hjf1223/aggbug/1440992.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47965/" target="_blank">Google App Engine宕机6小时——云的安全在哪里？</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>Telnet发送邮件和.NET邮件匿名发送组件</title><link>http://www.cnblogs.com/hjf1223/archive/2009/04/09/1432489.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 09 Apr 2009 07:33:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2009/04/09/1432489.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1432489.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2009/04/09/1432489.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1432489.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1432489.html</trackback:ping><description><![CDATA[<p>利用IIS带的SMTP虚拟服务器，可以匿名发送邮件，并且通过telnet就可以发送，一直只是看过别人做过，并且看过很多遍，自己没有尝试过还是无法即拿即用，今天还是亲手尝试了一下，并记录以下的发送步骤。</p> <p>使用Telnet发送邮件：</p> <p>打开cmd命令行</p> <p>输入telnet 127.0.0.1 25，连接本地邮件服务器</p> <p>输入HELO，建立会话，返回250成功代码。</p> <p>输入MAIL FROM:youname@server.com，邮件发送者，返回250成功代码。</p> <p>输入RCPT TO:friend1@server.com ，邮件接收者，返回250成功代码。在这一步如果出现 550 5.7.1 Unable to relay for ******* 则需要在IIS自带的SMTP，在SMTP虚拟服务器上点击右键，在弹出的属性窗口里进行如下设置：</p> <p>点击访问选项卡，再点击中继，在弹出的窗口出点击添加，然后选单台计算机，添加IP地址为 127.0.0.1。然后一路确定返回。</p> <p>输入DATA，开始输入数据，在下一行输入以下邮件内容：</p> <p>subject:this is subject</p> <p>this is body</p> <p>.</p> <p>输入"."回车后邮件即被发送出去。</p> <p>同时在此推荐一款由我们老板在几年前独立自主开发的邮件发送组件，<a href="http://www.umailcampaign.com/mailcom.aspx" target="_blank">qqMail.net</a>，它可是一个可能强大的邮件发送组件，实现了比较全的SMTP协议，包括使用localhost匿名发送邮件，绝对比.NET自带的SMTP Client功能强大不少，作者本人也对SMTP的原理了如执掌。</p> <p>也许这个组件<a href="http://dnsmtp.codeplex.com/">DnSmtp</a>也是相当的有用，但是我并没有用过。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1432489.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47961/" target="_blank">微软新推社交网站Windows Live Planet</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>CS-Script,C#动态编译引擎</title><link>http://www.cnblogs.com/hjf1223/archive/2009/04/07/cs_script.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Tue, 07 Apr 2009 14:35:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2009/04/07/cs_script.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1431246.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2009/04/07/cs_script.html#Feedback</comments><slash:comments>26</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1431246.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1431246.html</trackback:ping><description><![CDATA[<p><a href="http://www.csscript.net/">CS-Script</a>是基于ECMA CLR标准之上的动态编译C#脚本的编译引擎。利用CS-Script可以在系统中动态编译一段C#脚本，并以静态函数或实例对象的形式使用。放在一个系统框架中，可以起到部分动态语言的效果。先看看它的使用:</p><pre class="brush: csharp;">Assembly assembly = CSScript.LoadCode(<br>&nbsp;&nbsp;&nbsp; @"using System;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class Script<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void SayHello(string gritting)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(gritting);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }");<br>AsmHelper script = new AsmHelper(assembly);<br>script.Invoke("Script.SayHello", "Hello World!");</pre>
<p>使用Cs-Script很简单，只需要引用一个很小的程序集，它的使用同样简单。通过CSScript.LoadCode动态编译一段C#脚本，返回程序集对象，再利用AsmHelper对象以静态方法或返回实例对象的方式反射调用C#代码功能。</p>
<p>动态使用脚本可以给系统带来很大的灵活性，它和可与.NET互交互的Ironpython有着某种异曲同工之处，但又各有千秋。Ironpython可以充分发挥动态语言方便灵活的特点，但Cs-Script却完全具备了C#的完全功能。使用CS-Script最大的优势在于，它完全兼容.NET 2.0/3.0/3.5等版本，和Mono的基于功能。它以静态函数或对象实例的形式在系统中使用，运行于当前的AppDomain，给开发人员的使用带来极大的便利。而据我了解的Ironpython目前还只支持.NET 2.0，不支持C# 3.0的所有特性，这是当前Ironpython存在的一大不足，并且对于.NET开发人员来说，在python和C#两种语言之间不断切换也给开发调试带来非常大的麻烦。</p>
<p>开发语言的动态化是现代语言的一大趋势，但是从系统开发和维护的角度来说，个人还是倾向于静态为主，动态为辅的平台。在一些场合，动态语言（包括动态编译）都会给系统框架带来更大的灵活性。ASP.NET .aspx/ascx上的C#脚本就是动态编译的一个最直接的例子。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1431246.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47960/" target="_blank">火狐3.5版被指推出太匆忙：存在50多个漏洞</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>怎样写技术博客</title><link>http://www.cnblogs.com/hjf1223/archive/2009/04/07/1431147.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Tue, 07 Apr 2009 11:06:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2009/04/07/1431147.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1431147.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2009/04/07/1431147.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1431147.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1431147.html</trackback:ping><description><![CDATA[<p><font face="微软雅黑">刚开始入门时是在别人的技术博客里学习技术，那时候起步相对较晚，毕业后的很长一段时间才知识什么是.NET，所有技术对自己来说都是新知识，要学习的太多了。而通过技术博客还可以不断的了解到自己不曾知识的技术，通过别人的辩论也可以让自己可以有一个辩证的观点来认识某一种技术的优缺点，从而帮助自己逐渐形成相对客观的观点来看待每一种技术。社区的交流几乎是自己技术生涯中，最重要的一个老师。大家可能都认为技术书籍才是入门者最好的途径，但我个人的经验是通过社区交流和技术博客才能让一个初学者在最短的时间内了解到比较广泛的技术，而后再通过自身的努力选择方向再深入研究。但是技术博客和社区交流相对较散，时间和空间跨度大，在一定的阶段还是要通过一些技术书籍来才能系统的获取知识和技术。</font></p> <p><font face="微软雅黑">自己撰写技术博客已经有三四年的时间了，最开始写技术博客是为了总结自己在工作当中的一些心得和解决问题的过程。这是一个享受的过程，享受解决问题后的那种喜悦；享受在解决问题过程中煅练出来的举一反三，独立思考的能力；享受自己在工作中不断积累的那种兴奋。这时候写技术博客真正受益的只是自己，是自己进步一种手段。因为解决问题，不应仅仅解决了问题本身，还应该要知道为什么会出现该问题，这时候通过技术博客就能很好的进行分析和总结。</font></p> <p><font face="微软雅黑">后来，随着能力的提高和经验的积累，解决问题已不再需要花费自己很多的时间。此时对技术有了更多的追求，开始对一些社区中推荐的开源框架产生了浓厚的兴趣，并着手进行研究。通过自己的研究，真正开阔了自己的眼界，虽然此时还并不能很好的完全读懂这些框架的代码。但是有了这层历练后，对自己之后的再进一步跨跃打下了很好的基础。对开源框架的兴趣不仅仅停留在研究的层面上，在开发实践中也在不断的找机会去使用这些开源框架，在这程当中获得了大量的第一手实践心得，并将这些心得以技术博客的形式总结出来。曾经试用过的开源框架包括：iBatis.net,Enterprise library,Castle,NBear,ASP.NET AJAX还有很多很多，但是经过一些实践后，现在仍然在使用的已经不多了。这些技术实践对自己现在的技术形态起着关键而深远的影响。</font></p> <p><font face="微软雅黑">在自己有一定能力的时候，开始参与一些开源项目的工作。参与了NBear Mapping组件的开发，LumaQQ.NET开发包，开源了自己在开发实践中的一些零碎组件。在这个时候，以技术博客的形式发表项目文档和入门指南，并与使用者进行交流。</font></p> <p><font face="微软雅黑">然而，在近来的一段时间里，由于忙碌等原因，自己慢慢的失去了通过撰写技术博客的方式来总结自己的技术体验。同时也产生了如何撰写技术博客的一些迷茫，要写一篇有质量，有内容所要需要花费大量的时间和精力，并且必须有很大的动力或者冲动，如果失去了这种冲动，那一篇构思完善的文章最后有很大可能是要夭折的。在过去的三天时间里，获得了近几个月以来少有的假期清闲，但是自己可以花一天的时间观看《走西口》，却懒得将一篇已写了两天的技术总结完成了。这就是慵懒的后果。</font></p> <p><font face="微软雅黑">一直在思考该怎样写技术博客。也许现在给自己的答案是：想到哪，写到哪，一定要趁着当时的冲动，一口气完成。既然是博客，那就不需要组织太严谨。既然没有文采，那就用最为平实的语言来描述表达。只要自己日后还能看懂，有兴趣的人也能看明白就行了，要求别太高了。</font></p> <p><font face="微软雅黑"></font></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1431147.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47960/" target="_blank">火狐3.5版被指推出太匆忙：存在50多个漏洞</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>你是否知道:删除或重命名站点下的任意目录导致站点重启(Session丢失)及解决办法</title><link>http://www.cnblogs.com/hjf1223/archive/2009/02/12/1388984.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 12 Feb 2009 05:15:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2009/02/12/1388984.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1388984.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2009/02/12/1388984.html#Feedback</comments><slash:comments>13</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1388984.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1388984.html</trackback:ping><description><![CDATA[<p>也许你知道，修改站点的某些特定文件和目录会导致整个站点重启或者重新编译。也许你不注意，你不会知道删除或重命名站点下的任意目录，会导致整个站点重启（添加目录并不会）。这个问题其实是很多Session丢失的根源，比如《<a href="http://www.cnblogs.com/tintown/archive/2008/01/08/1030721.html">关于ASP.NET 2.0的目录结构变化导致Session丢失的问题</a>》，同样你还可以找到很多这样的例子。</p> <p>这个其实是ASP.NET 2.0的一个“精心”设计，因为在很多情况下。ASP.NET会缓存很多资源，而如果没有监控目录的变动的话，那么有些已删除的资源就有可能仍然被使用着，造成其它不必要的资源泄露。通过这篇<a href="http://blogs.msdn.com/tmarq/archive/2007/11/02/asp-net-file-change-notifications-exactly-which-files-and-directories-are-monitored.aspx" target="_blank">文章</a>我们可以找到可能导致站点重启的一些条件，其中的第一条就是删除或重命名目录会导致站点重启。</p> <p>这个问题早在ASP.NET 2.0刚发布的时候就被发现，并且已经有了专门的讨论《<a href="http://blogs.msdn.com/toddca/archive/2005/12/01/499144.aspx" target="_blank">Deleting ASP.NET 2.0 Application Sub-Directories Shuts Down the AppDomain</a>》，在文中也提了一种解决方案，但是做法太过复杂。最理想的方案是，有相关的补丁来解决这个问题，幸运的是，我们可以通过<a href="http://forums.iis.net/p/1152020/1882114.aspx" target="_blank">这里</a>找到这个补丁，并且介绍如何配置来解决这个问题。</p> <p>解决方案是：监控目录删除或重命名的机制叫：File Change Notifications （FCNs），这个补丁就是用来设置FCNS禁用或启用的开关，我们只要把FNCS禁用就可以避免这个问题。</p> <p>做法：现在的ASP.NET 2.0已经到了SP2，我们不需要单独去安装这个补丁。我们只需要在注册表在做一步操作即可解决这个问题。在HKLM\Software\Microsoft\ASP.NET 添加一个名为：FCNMode 的DWORD值，默认它应该是不存在的，它的值含义为：</p> <p>Does not exist <br>This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.  <p>0 or greater than 2 <br>This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.  <p>1<br>The application will disable File Change Notifications (FCNs).  <p>2<br>The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory.  <p>我们将它的值设为1即可禁用FCNS。更为详细的可以参考：<a title="http://support.microsoft.com/kb/911272" href="http://support.microsoft.com/kb/911272">http://support.microsoft.com/kb/911272</a>  <p>退出注册表，重启IIS，问题即可解决。</p> <p><font color="#ff0000">说明一下：Session丢失只是AppDomain重启的一个副作用，并不是本文的重点，只是为了方便别人查找相关问题时的一个标题优化。另外导致站点重启的原因有很多种，可以参考上文给出的链接，这里不再遨述。</font></p> <p><strong><font color="#ff0000">再次说明一下：如果你禁用了FCNs，那么不管你是修改了Web.config，还是BIN目录，都不会引起整个站点的重启。我想这个也会相应的给我们带来一些新的问题，比如缓存过期的问题。至于是否禁用，大家自己选择吧。:(</font></strong></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1388984.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47959/" target="_blank">Google对手机搜索进行优化升级</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>你是否知道:Request.Form和Request.QueryString的Key不区分大小写</title><link>http://www.cnblogs.com/hjf1223/archive/2009/02/12/1388972.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 12 Feb 2009 04:52:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2009/02/12/1388972.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1388972.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2009/02/12/1388972.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1388972.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1388972.html</trackback:ping><description><![CDATA[<p>原来一直不注意，在一直重构中无意中发现，Reqeust.Form的Key不区分大小写。想想有道理，在Web请求中，URL是不区别大小写的，那么Request.Form的Key也不应用区别大小写。那么如果你想通过Request.Form来取得ASP.NET Server控件的值的话，一样也不需要注意大小写。</p> <p>同理，Reqeust.QueryString也是不区别大小写的。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1388972.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47959/" target="_blank">Google对手机搜索进行优化升级</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>制作Visual Studio项目模板</title><link>http://www.cnblogs.com/hjf1223/archive/2008/11/19/project_template.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Wed, 19 Nov 2008 15:19:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/11/19/project_template.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1337095.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/11/19/project_template.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1337095.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1337095.html</trackback:ping><description><![CDATA[<p>在安装MVC，ASP.NET AJAX 后都会在新建工程列表中出现一些新的项目模板，通过这些项目模板创建工程后，都会为我们做好一些这些工程需要的配置，或者干脆就创建一些示例工程，为我们简化了很多配置的工作，并具有一些的学习向导作用。在很多情况下，也许我们也需要自己创建这样的项目模板，其实步骤非常简单，下面我们就通过一个简单的例子来说明如果创建项目模板，并创建安装文件。</p> <p>项目模板的创建非常简单，我们只需要将希望作为项目模板的工程，导出即可，在Visual Studio 中找到：File &gt;&gt; Export Template</p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%20Wizard_2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="386" alt="Export Template Wizard" src="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%20Wizard_thumb.jpg" width="442" border="0"></a> </p> <p>如果当前解决方案中有多个工程，我们可能通过下拦框选择希望被作为模板的项目，选择“Project template ”进入下一步：</p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%20Wizard2_2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="390" alt="Export Template Wizard2" src="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%20Wizard2_thumb.jpg" width="443" border="0"></a> </p> <p>在这里，你可以选择是否自动将模板导入到Visual Studio ，还可以选择是否弹出显示导出的项目模板，点击完成即可完成项目模板的导出，并且此时，它会为我们自动导入到Visual Studio中，并且会弹出导出的项目模板目录，它是一个zip压缩文件。此时，我们再打开一个Visual Studio，新建项目时即可使用刚刚导出的模板。</p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%203_2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="288" alt="Export Template 3" src="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%203_thumb.jpg" width="457" border="0"></a> </p> <p>到些为止，项目模板的创建已经完成。但是还有一点麻烦的是，每次我们要安装此模板时，需要手工将该压缩文件拷贝到项目模板目录，使用起来不是很方便。我们希望能像安装文件那样，双击即可完成安装，不需要手工拷贝文件。此时我们还需要一个文件，.vscontent，来制作.vsi安装文件。我们在刚刚导出的项目模板目录中新建名为：SampleProjectTemplate.vscontent的xml文件。它的内容如下：</p> <p>&lt;?xml version="1.0" encoding="utf-8" ?&gt;<br>&lt;VSContent xmlns="<a href="http://schemas.microsoft.com/developer/vscontent/2005&quot;">http://schemas.microsoft.com/developer/vscontent/2005"</a>&gt;<br>&nbsp;&nbsp;&nbsp; &lt;Content&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;FileName&gt;SampleProjectTemplate.zip&lt;/FileName&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;DisplayName&gt;Sample Project Template&lt;/DisplayName&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Description&gt;A project template created for this example.&lt;/Description&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;FileContentType&gt;VSTemplate&lt;/FileContentType&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ContentVersion&gt;1.0&lt;/ContentVersion&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Attributes&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Attribute name="ProjectType" value="Visual C#"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Attribute name="ProjectSubType" value="Web"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Attribute name="TemplateType" value="Project"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Attributes&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/Content&gt;<br>&lt;/VSContent&gt;  <p>以上的属性配置就不多介绍了，需要说明的是ProjectSubType属性是指定将该模板安装在Web的项目列表当中。将项目模板的压缩文件和SampleProjectTemplate.vscontent压缩成一个<strong>ZIP</strong>文件，并且修改后缀名为：<strong>.vsi 。</strong>然后你可以看到的它的图标发生面什么变化了，双击该文件，我们会得到这样的一个安装向导界面：</p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%204_2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="273" alt="Export Template 4" src="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/VisualStudio_147E9/Export%20Template%204_thumb.jpg" width="309" border="0"></a> </p> <p>OK，这就是我们需要的一个项目模板安装文件，直接完成，就可以完成项目模板的安装和导入。</p> <p>现在，你就可以开始动手创建自己的项目模板了，享受项目模板带来的便利了 :)。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1337095.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47958/" target="_blank">风声又起 Windows 7 RTM版7月13日完成</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>硬盘事件启示——Live mesh在线存储</title><link>http://www.cnblogs.com/hjf1223/archive/2008/11/18/1336202.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Tue, 18 Nov 2008 12:12:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/11/18/1336202.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1336202.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/11/18/1336202.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1336202.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1336202.html</trackback:ping><description><![CDATA[<p>作为一个从事IT行业的专业技术人员 <br>应该非常清楚数据的重要性 <br>而个人数据基本都是存在单机硬盘上， <br>并不会做经常做备份 <br>即使做了备份，而不会去注意定期去更新和维护历史版本 <br>毕竟个人不比企业 <br>这次的硬盘的教训深深的触动了我<br>可以说我遇到了最坏的情况 <br>最重要的数据都是在D盘 <br>而偏偏是D盘的磁道出现了两个坏道 <br>使整个系统无法启动 <br>并且在正常的操作系统环境下 <br>D盘可以认到，但是无法读取和拷贝数据 <br>好在最后使用数据还原工具还原了这部分数据 <br>主要是“我的文档” <br>虽然换硬盘花去了近两周的时间 <br>还好，总算到最后没有大的损失 <br>电脑也还在保修期内 <br>总结此次事件 <br>给自己提了一个很大的醒 <br>数据备份可以有几种： <br>1.多硬盘备份 <br>2.定期刻录 <br>3.在线存储 <br>前两种需要比较大的成本，并且维护难度极大 <br>在线存储是一种比较省资源的方式，现在都有很多大容量的邮箱和在线硬盘，比如：Gmail，如果是图片，还可以存储在Filckr上，做在线相册。但是这些做法也无法解决维护困难的问题，都需要用户主动去备份和提交数据，并且安全性无法保证。 <br>现在各大软件服务商都在主推“云服务”，“云计算”，“云存储”。这些概念经过了长时期的炒作，终于进入了实质的技术实现。微软在这方面的技术主要就是Live Services框架技术，这一套基于.NET技术之上的云技术，是未来几年的技术发展方向。现在这些技术也都进入了Preview或Beta阶段，有代表性的包括：Azure，Live mesh技术,Skydriver，这些技术统称为Live Services。 <br>其中，Azure面向开发人员的接口，也就是像我这样的从业人员可以在此基础上作一些“云技术”的服务。 <br>Skydriver，顾名思义，“天空上的存储器”，也就是放在天上的硬盘，就是在线存储器。但是此服务目前还没有对国内用户开放支持。 <br>Live mesh，就是我现在准备使用的技术，它是一个可以在线同步数据，将本地硬盘的数据与Microsoft提供的存储空间进行同步，并且可以解决多种不同设备，不同机器，不同用户之间的数据同步，并且还提供远程的机器管理功能（类似远程桌面），重要的是这项目目前是免费的，并且是面向所有最终用户。 <br>经过这次的教训后，决定将重要数据存储到Live mesh上同步，以防再出现类似的情况出现。同时这样做也有助于解决平常在个人电脑和公司电脑之间的数据共享和同步问题。但是这样做也有风险，我的数据都可以在别人的控制范围之内，至少在对于微软来说是可见的。但是机器上不存放“艳图”，自己也不是什么名星，问题应该不大。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1336202.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47957/" target="_blank">乔布斯和埃利森</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>ORM With Versioning Control</title><link>http://www.cnblogs.com/hjf1223/archive/2008/10/16/1312764.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 16 Oct 2008 15:23:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/10/16/1312764.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1312764.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/10/16/1312764.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1312764.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1312764.html</trackback:ping><description><![CDATA[<p>在一些场合，我们可能需要对业务实体进行版本控制。类似于源码管理工具一样，可以查看历史版本，可以回滚，可以Lock，一个业务实体对象，同一时刻只允许一个人进行更新操作。为了实现信息的可追溯性，这些功能应该是必不可少的。只是我们该在哪里去控制实体对象的版本呢？</p> <p>我们希望将版本控制的功能，独立于某一个具体的业务实体，这样才可以实现最大共用和扩展性。显然，要实现这一功能最好的切入点应该是在数据持久层，也就是在实体持久化时，我们需要有一个统一的，通用化的接口来完成，同时在这里插入版本控制的功能。无疑，这里的最合适的持久化接口应该是ORM，那就相当于我们要实现一个带实现版本控制的ORM接口。</p> <p>版本控制功能，我们不仅要求与数据库无关，还要求与具体的某一种ORM框架无关。与数据库无关，我们可以很容易通过ORM来隔立，但是与ORM框架无关，我们就需要将版本控制的功能从与某一种ORM框架隔离开来。</p> <p>版本控制功能，是插入到ORM接口中去的，那在哪里去检测实体的修改情况呢？一种方案是将原始数据和修改后的数据，传入版本控制接口，由版本控制模块进行比较，从而得出实体的变化情况。</p> <p>另一种方案，就是在实体中插入一定的属性变化跟踪机制，这也是现有的ORM实体中已经有实现的一部分，不同的ORM框架在监控实体更新变化方面都有不同的机制，在NBear，LINQ To SQL，Entity Framework都有一套自己的实体属性变化跟踪机制。我们可以将这些不同的跟踪机制统一起来，形成一套标准的ORM版本控制模块的接口实现。</p> <p>还有一些需要考虑的：</p> <p>存储历史版本时，是使用增量存储还是使用完全存储。增量存储，在回滚历史版本时，就需要从当前版本起，做很多的回溯的工作，而完全存储就可能会耗很多存储空间。</p> <p>在存储方式上，我们是将它们存储到数据库，还是以XML文件的格式单独存放每一个版本的记录。</p> <p>目前的一个存储想法是：使用增量存储与完全存储共存，将每次改变的字段，以及它的原始值和新值保存到数据库中，方便在查看历史版本修改记录时用。而将每个版本完整值，以一定的目录格式，XML文件的格式保存在磁盘中，可以考虑压缩等因素。这样做的原因是，回滚历史版本的操作一般是相对比较少的，但是存储完整的历史版本值，却可能需要很多的数据库空间和考虑备份的问题。假设我们以操作日期的目录格式来保存文件，我们就可以方便的进行备份和转移。</p> <p>遗留问题，在ORM中，对象的关联是必不可少的内容。对于对象之间的关联关系发生变化是否也需进行版本控制，这样一来，版本控制的内容就会变得更复杂和难以实现。所以暂且限定，版本控制只针对于单对象的属性值变化。</p> <p>以上就是ORM With versioning control的一些想法，这些想法是从<a href="http://en.wikipedia.org/wiki/JSR-170" target="_blank">Content Repository API For Java</a> (JCR)衍生而来的。在JCR中是实现了一个自有格式(XML)的数据库，用在CMS中存储一些结构可变（非结构化）的内容。同时在它的功能定义中，还包括了一些传统数据库（或数据库使用接口）所不具有的功能，包括：版本控制，数据变化检测等功能。我想法，在结构化数据的存储中，要实现这些功能，应该是在ORM上来实现，欢迎大家来讨论。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1312764.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47956/" target="_blank">Xbox Live将投放Silverlight广告</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>重新投入战斗</title><link>http://www.cnblogs.com/hjf1223/archive/2008/10/11/1308455.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Fri, 10 Oct 2008 16:31:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/10/11/1308455.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1308455.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/10/11/1308455.html#Feedback</comments><slash:comments>17</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1308455.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1308455.html</trackback:ping><description><![CDATA[<p>朋友们，我回来了。离开博客园两个多月的时间，这段时间经历了人生第一次换工作，战场也从福州转移到厦门来了。这是一段难忘的经历，离开了生活9年的城市来到一个新的环境，总有太多的不适应。在这段时间自己个人发生了很多乌龙的事情，还好一切都不算太坏，这些不顺的事情也都逐渐的远去了，在这边的生活也慢慢的也开始行成新的规律。</p> <p>过去的一段时间，由于一些个人事情的牵伴，无法专心投入技术的研究和总结，落下了很多东西，不过总算是没有脱离主流。从现在开始，又要投入更有挑战性的工作当中去，在这过程当中，我相信会有很多东西值总结和思考，我希望能把这些东西记录下来，不断的促进自己的进步。技术的追求是无止尽的，我永远不会赞同够用就好的理念，那样是给自己找放松的理由，同时也会让自己只问题的表象，而不了解内在的本质。只会参考demo写代码的人，经验再丰富那都只是重复的机械运动，没有任何价值。我相信老板们更愿意找年轻，廉价的程序员来做这些事情。</p> <p>扯远了，一点小感概（最近园子里面不是在掀起新一轮的程序员年龄与能力话题讨论吗）。在厦门的新环境，自己还是比较满意的。谦逊大方的老板，团结友好的同事，宽松自由的环境，这是自己能够快速适应这里环境的主要原因。在这里，可以找到探讨和学习的对象，在短短的一个月时间里，已经能明显的感觉到自己的一些方面突破。一个良好的技术环境，可以直接或间接的给我很多启发，也在不断的促进着我技术的进步，希望这是自己的技术生涯走向一个新的阶段的开始 :)。。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1308455.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47951/" target="_blank">Debian无视GNU创始人警告 接受Mono</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>LumaQQ.NET协议过期及解决办法</title><link>http://www.cnblogs.com/hjf1223/archive/2008/07/29/lumaqq_net_newclientversion.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Tue, 29 Jul 2008 15:24:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/07/29/lumaqq_net_newclientversion.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1256008.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/07/29/lumaqq_net_newclientversion.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1256008.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1256008.html</trackback:ping><description><![CDATA[<p><font color="#ff0000">版权声明：该开源开发包，是基于LumaQQ的基于等价移植到.NET平台下，开发者不直接参与QQ协议的分析工作，移植到.NET平台纯粹是为了方便广大.NET开发者学习和研究之用，并且没有产生任何直接的经济效益，并且纯粹是个人的技术学习研究行为，与本人所在单位没有任何关系。此开发包的用户在使用过程产生的效益和涉及的法律责任与本人没有直接关系。如果影响到您或您的公司利益，敬请谅解并且与我联系，本人会第一时间作出处理。本系列章首发且单发于博客园，由于各种原因不欢迎转载本系列文章，如果您转载了该系列文章请自行承担责任并且转载完整版本，包括版权声明。</font></p> <p>好久都没有继续LumaQQ.NET的开发，这一段时间一直没有心思静下心来做开发工作。导致LumaQQ.NET发布了三个版本之后，开发就一直处于停滞状态，关注的也少。今天在小组内，有朋友发出了<a href="http://space.cnblogs.com/group/topic/4008/">登录失败：您的QQ版本已经停止使用</a>这个贴子后，在晚上的时间了解了下确实是，腾讯停止了QQ2005协议了，在迷茫之际终于有人就提出将客户端版本号标志改为0x0E1C即可登录，试下果真可以。我之前也有试过修改这个版本号，可能是没有找到正确的版本号，导致登录时出错未知异常。如果有人知道，能不能麻烦把目前所有版本的QQ版本号标号告知一下，我也省得再去花时间找。</p> <p>为了方便大家，先放出目前的可用版本，有需要的请下载更新程序集引用即可</p> <p><a href="http://files.cnblogs.com/hjf1223/LumaQQ.NET1.0.0.4.rar">程序集和文档下载</a></p> <p><a href="http://svn.cnblogs.com:8080/svn/LumaQQ_NET/">源代码（SVN）</a></p> <p>另外，也许还需要一段时间才能继续LumaQQ.NET的开发，请大家见谅，也谢谢大家对LumaQQ.NET的关心和关注！</p> <p>&nbsp;</p> <p>链接：</p> <p>LumaQQ.NET讨论小组：<a title="http://space.cnblogs.com/group/100260" href="http://space.cnblogs.com/group/100260">http://space.cnblogs.com/group/100260</a></p> <p>LumaQQ.NET官方开发博客：<a title="http://hjf1223.cnblogs.com/" href="http://hjf1223.cnblogs.com/">http://hjf1223.cnblogs.com/</a></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1256008.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47950/" target="_blank">iPhone 3GS首发日创AT&T多项纪录</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>ASP.NET MVC ：MVC页面验证与授权</title><link>http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_authorization.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Wed, 09 Jul 2008 14:22:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_authorization.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1238509.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_authorization.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1238509.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1238509.html</trackback:ping><description><![CDATA[<p>在ASP.NET MVC中，如何来实现表单的验证与授权访问呢？至少在CTP3中，还没有一个官方的解决方案。ASP.NET WebForm的表单验证和授权机制是否适合在ASP.NET MVC中使用呢？带着这些问题来进入我们今天的主题。</p> <p>在ASP.NET WebForm的架构下，我们可以通过一定的配置即可实现用户身份验证和授权。特别是在ASP.NET 2.0的Membership功能的支撑下，可以做到更加简洁可复用的用户验证系统。通过web.config可以做到对页面或目录对不同用户身份可见性的定制，但是它是基于物理文件和目录。而在ASP.NET MVC架构下，用户访问的每一个页面在磁盘中并没有一个固定的物理文件，它是通过Controller控制数据与视图的组合来生成HTML代码，进而向客户端输出。那么我们该如何来复用已有的表单验证授权机制呢？</p> <p>在MVC中，请求的功能入口是Controller相应的Action函数，我们可以在函数执行前去控制请求权限。在ASP.NET MVC Preview 2后，提供了一个机制让我们可以对Action的AOP拦截，这个接口定义如下：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IActionFilter</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">void</span> OnActionExecuted(ActionExecutedContext filterContext);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     <span style="color: #0000ff">void</span> OnActionExecuting(ActionExecutingContext filterContext);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     <span style="color: #0000ff">void</span> OnResultExecuted(ResultExecutedContext filterContext);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     <span style="color: #0000ff">void</span> OnResultExecuting(ResultExecutingContext filterContext);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span> }</pre></div></div>
<p>我们有两种方式来实现拦截，一种我们可以通过定义Attribute来实现拦截的功能，在System.Web.Mvc程序集中有一个ActionFilterAttribute抽象类，通过重写这个抽象类的这些虚方法，我们就可以实现对特定的执行过程进行拦截。</p>
<p>另一种方法，我们注意到Controller这个类也实现了IActionFilter这个接口，并且也提供了这四个函数的虚拟方法定义。框架内部，在调用Action方法的时候同时来调用这些拦截方法。具体的可以参考：ControllerActionInvoker 这个类的实现，所有的Action的调用都在这个类当中被实现。所以我们只要重写Controller里这四个虚方法，也可完成本Controller面的所有Action的拦截。</p>
<p>在这里，我也找到了国外友人已经实现好的基于角色的MVC权限控制的方案。自定义了两个自定义Attribute，分别为：RequiresAuthenticationAttribute和RequiresRoleAttribute。通过这两个Attribute来可以作用于Class和Method，用标记哪些Controller或Action需要登录后，或者需要拥有哪些角色才能执行。如果用户没有拥有访问当然Controller或Action权限的时候，就会自动被重定向到登录页面去。下面是两个类的定义：</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #008000">/// Checks the User's authentication using FormsAuthentication</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000">/// and redirects to the Login Url for the application on fail</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">[RequiresAuthentication]</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RequiresAuthenticationAttribute : ActionFilterAttribute</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnActionExecuting(ActionExecutingContext filterContext)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #008000">//redirect if not authenticated</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #0000ff">if</span> (!filterContext.HttpContext.User.Identity.IsAuthenticated)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #008000">//use the current url for the redirect</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">string</span> redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #008000">//send them off to the login page</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">string</span> redirectUrl = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">"?ReturnUrl={0}"</span>, redirectOnSuccess);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">string</span> loginUrl = FormsAuthentication.LoginUrl + redirectUrl;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            filterContext.HttpContext.Response.Redirect(loginUrl, <span style="color: #0000ff">true</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000">/// Checks the User's role using FormsAuthentication</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #008000">/// and throws and UnauthorizedAccessException if not authorized</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RequiresRoleAttribute : ActionFilterAttribute</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">{</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> RoleToCheckFor { get; set; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnActionExecuting(ActionExecutingContext filterContext)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        <span style="color: #008000">//redirect if the user is not authenticated</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">if</span> (!String.IsNullOrEmpty(RoleToCheckFor))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">if</span> (!filterContext.HttpContext.User.Identity.IsAuthenticated)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #008000">//use the current url for the redirect</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">string</span> redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #008000">//send them off to the login page</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #0000ff">string</span> redirectUrl = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">"?ReturnUrl={0}"</span>, redirectOnSuccess);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">string</span> loginUrl = FormsAuthentication.LoginUrl + redirectUrl;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                filterContext.HttpContext.Response.Redirect(loginUrl, <span style="color: #0000ff">true</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: #0000ff">else</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                <span style="color: #0000ff">bool</span> isAuthorized = filterContext.HttpContext.User.IsInRole(<span style="color: #0000ff">this</span>.RoleToCheckFor);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">                <span style="color: #0000ff">if</span> (!isAuthorized)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">                    <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> UnauthorizedAccessException(<span style="color: #006080">"You are not authorized to view this page"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        <span style="color: #0000ff">else</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> InvalidOperationException(<span style="color: #006080">"No Role Specified"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre></div></div>
<p>如上所介绍的两种方法，我们一样可以定义一个Controller基类，通过拦截来进行权限的控制。但是与定义Attribute相比，手法并不是很好，也不利于通用化。但是就理论上的性能来说，会比Attribute更好。</p>
<p>到目前为止，ASP.NET MVC还没有更新的消息，我想在正式版本的ASP.NET MVC框架，权限控制问题会有一个官方说法。希望到时候会有一种更为灵活和可配置的方案。也许通过控制Url来控制访问权限也是一种可行的方案，会不会集成到RouteTable里面呢？让我们试目以待吧。</p>
<p>上一篇：<a href="http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_webform.html">ASP.NET MVC :从ASP.NET WebForm到ASP.NET MVC技术上的共用和差异</a></p>
<p>广告：<a href="http://www.zazuone.com/">我的基于MVC的网站</a></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1238509.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47949/" target="_blank">Silverlight开发大赛奖金高达10000美元</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>ASP.NET MVC :从ASP.NET WebForm到ASP.NET MVC技术上的共用和差异</title><link>http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_webform.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Wed, 09 Jul 2008 05:40:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_webform.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1238507.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/07/09/mvc_webform.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1238507.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1238507.html</trackback:ping><description><![CDATA[<p>关于WebForm与MVC的讨论，年初的时候已经有一段很长时间的讨论了。我无意再去争论哪种架构模式更适合我们做开发，不管是哪个领域，技术的存在都有其不同的历史意义和市场价值。我更关注的是，在合适的机会去掌握更多的技术，从技术实现的角度来寻找当前阶段最为顺手的一种做事方法。所以请注意，在这里不讨论WebForm与MVC的优劣，适用场景。在这里只有ASP.NET WebForm与ASP.NET MVC，同样属于ASP.NET框架下的两种不同的Web开发技术，是如何充分发挥ASP.NET平台的强大功能，以及对于掌握ASP.NET WebForm的开发人员，转向ASP.NET MVC架构的学习成本。这就是我本篇文章的立意所在，同时我也是希望为我之后的几篇MVC系列文章提供一些注脚和铺垫。</p> <p>之前，从事ASP.NET开发，在没有特殊说明的情况下，指的就是ASP.NET WebForm的开发。之前ASP.NET技术的发展，直接就体现在WebForm技术上的进步。在ASP.NET MVC 出现之后，之前大家所掌握的ASP.NET技术对于ASP.NET MVC仍然有效，并且是最基础的部分。包括：页面处理流程，Web请求上下文对象，Web配置系统，公用性的组件模块，部分的服务器控件等等。我想从这几大块来详细阐述ASP.NET MVC对于ASP.NET技术的继承：</p> <ol> <li>页面处理流程：ASP.NET MVC 的页面处理流程仍然是在ASP.NET原有的处理流程上的扩展，在在上游的请求通道不变的前提下，通过特定的IHttpModule和IHttpHandler来处理ASP.NET MVC的请求。与WebForm页面处理不一样的地方就在于，在WebForm中，每一个页面都是一个IHttpHandler实例，页面的事件流程就是从IHttpHandler的ProcessRequest(HttpContext httpContext)方法开始。而在ASP.NET MVC中，所有的Controller都并不是IHttpHandler的继承实例，它的Action是在MvcHandler中被执行的，当然我们也可以自定义是MvcHandler。  <li>Web请求上下文对象：在ASP.NET MVC中，处理请求的线程模型没有改变。请求的上下文对象，与原有的ASP.NET WebForm仍然是共用的。  <li>Web配置系统：ASP.NET MVC仍然使用原有的配置系统，在Web.config中只是部分的配置节点不适用于ASP.NET MVC，比如页面访问授权配置。  <li>公用性的组件模块：在ASP.NET MVC中，包括Membership，healthMonitoring，httpModule,trace在内的内置和自定义的组件模块仍然是继续可用。  <li>部分服务器控件可用：首先，最为明显的是我们使用的是.aspx页面作为MVC的View。虽然后缀仍然为.aspx，但是它的意义已经不再是一个可执行的页面文件了，不再是一个纯粹意义上的IHttpHandler。但是它仍然是继承于原有的Page基类。在ASP.NET MVC中，将它作为View来展示，仍然以ProcessRequest为入口来执行页面，也就意味着除了回发事件的相关事件和函数不会被执行外，页面的执行事件流程仍然是有效的。以此，如果不考虑服务器控件的性能和其它因素影响，我们仍然是可以使用大部分的服务器控件，当然用不用取决于你。</li></ol> <p>以上是我总结到的一些ASP.NET MVC对ASP.NET原有技术的继承，但是做为ASP.NET技术的发展，有很多东西是本身就是乏善可陈的，不说，也应该知道就是那样。但是说出来，更有助于大家来区分ASP.NET，(ASP.NET)WebForm，ASP.NET MVC(为什么WebForm前面的ASP.NET加括弧呢？大家来说说原因)这三者的概念区别和关系。</p> <p>下面我还想来说说，ASP.NET MVC较之前的ASP.NET(WebForm)开发技术在实践上有哪些比较明显的区别：</p> <ol> <li>.aspx文件，已经不再是一个可被独立请求的页面了。你不能对它从物理上进行权限控制。  <li>我们的少用服务器控件了。我们仍然可以使用，你完全可以不考虑runat='server'的性能影响。但是并不保证所有的服务器控件都可用。可能还有其它的原因让你选择不使用服务器控件。  <li>我们没有PostBack和页面回发事件机制了。提交表单我们基本使用Web的原生方式了，传输的数据量也更为合理。  <li>我们少用ViewState了。少用，意味着我们还是可以用的。只是由于MVC架构的限制，我们在ViewState存的值并不会被序列化到客户端去，它有效性是在一次请求的上下文中。在某些特定的场合内，ViewState还是能发挥它的余热，并且并不影响性能。  <li>要处理一个用户的自定义请求，比如RSS请求。我们不再需要定义一个IHttpHandler或特定的.aspx页面。处理用户的每个请求都只是在一个Controller的Action函数当中，在Action函数中，你可以输出View，可以输出JSON字符串，还可以输出任何自定义格式的文件和输出流。  <li>业务逻辑与UI逻辑从架构上得到了很好的分离，但是你要不想这么做，仍然也是有效的。只是在这种情况下，你还是选择WebForm吧。</li></ol> <p>ASP.NET MVC和WebForm在很多实现上的统一，是我们已经掌握ASP.NET原有开发模式的开发人员顺利的上手MVC保证。之后陆续会有几篇我在用MVC实践自己一个<a href="http://www.zazuone.com">网站</a>后，对MVC的一些总结和心得。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1238507.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47949/" target="_blank">Silverlight开发大赛奖金高达10000美元</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>Visual Studio 2008 Error: The web services enumeration components are not available. You need to reinstall Visual Studio to add web references to your application.</title><link>http://www.cnblogs.com/hjf1223/archive/2008/06/26/1230291.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 26 Jun 2008 03:57:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/06/26/1230291.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1230291.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/06/26/1230291.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1230291.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1230291.html</trackback:ping><description><![CDATA[<p>今天在Visual Studio 2008中引用WebService，出现这样的错误提示：</p> <p>The web services enumeration components are not available. You need to reinstall Visual Studio to add web references to your application.</p> <p>在中文社区中没有找到相关的解决办法，通过国外的一个博客找到了解决方案：</p> <p><em>运行：devenv /resetskippkgs</em></p> <p>这个办法至少对<a href="http://paradigma.pt/ja/slog/index.php/2007/03/error-the-web-services-enumeration-components-are-not-available.html">他</a>，对我都是有效的。</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1230291.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47947/" target="_blank">微软告攒机商第一案胜诉</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>读取纯真IP数据库的公用组件QQWry.NET</title><link>http://www.cnblogs.com/hjf1223/archive/2008/06/19/QQWry_net.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 19 Jun 2008 12:25:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/06/19/QQWry_net.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1226174.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/06/19/QQWry_net.html#Feedback</comments><slash:comments>34</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1226174.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1226174.html</trackback:ping><description><![CDATA[<p>这是一个读取纯真IP数据库的公用组件接口，我是通过luma的《<a href="http://lumaqq.linuxsir.org/article/qqwry_format_detail.html">纯真IP数据库格式详解</a>》了解了纯真IP数据库数据格式，并且基于网络上的一个IPLocation.dll源码的基础改编而来。我为什么要改编这个组件呢？因为我看到这个组件在使用过程中，每次都要打开文件流，并且整个接口使用静态的属性。并不适合Web环境下，多线程并发查询的需求，并且在性能上也不是最优。有了luma的格式详解，和现有的IPLocation.dll的源码，使我的工作变得异常的简单。出现的一个小错误，也是经过一次调试后就解决了。性能较IPLocation.dll也有较大的提高，虽然只有短短的几百行代码，虽然网上也有很多类似的代码，但继承我一贯的做法，我仍然把这个组件开源贡献出来。下面是一些接口使用的介绍：</p><pre class="code">QQWry.NET.<span style="color: #2b91af">QQWryLocator </span>qqWry = <span style="color: blue">new </span>QQWry.NET.<span style="color: #2b91af">QQWryLocator</span>(<span style="color: #a31515">"qqwry.dat"</span>);<span style="color: green">//初始化数据库文件，并获得IP记录数，通过Count可以获得

</span>QQWry.NET.<span style="color: #2b91af">IPLocation </span>ip = qqWry.Query(<span style="color: #a31515">"120.67.217.7"</span>);  <span style="color: green">//查询一个IP地址
</span><span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"{0} {1} {2}"</span>, ip.IP, ip.Country, ip.Local); </pre><pre class="code">以下是与IPLocation.dll在性能上的对比代码：</pre>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.39%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 244px; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> Stopwatch stopwatch = <span style="color: #0000ff">new</span> Stopwatch();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> List&lt;<span style="color: #0000ff">string</span>&gt; ips = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt; { <span style="color: #006080">"218.5.3.128"</span>, <span style="color: #006080">"120.67.217.7"</span>, <span style="color: #006080">"125.78.67.175"</span>, <span style="color: #006080">"220.250.64.23"</span>, <span style="color: #006080">"218.5.3.128"</span>, <span style="color: #006080">"120.67.217.7"</span>, <span style="color: #006080">"125.78.67.175"</span>, <span style="color: #006080">"220.250.64.23"</span> };</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> stopwatch.Start();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 100; i++)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>    <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> item <span style="color: #0000ff">in</span> ips)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         ip = qqWry.Query(item);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>       <span style="color: #008000">// Console.WriteLine("{0} {1} {2}", ip.IP, ip.Country, ip.Local);</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span> stopwatch.Stop();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span> Console.WriteLine(<span style="color: #006080">"QQWryLocator 花了{0} ms"</span>, stopwatch.ElapsedMilliseconds);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span> stopwatch.Reset();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span> stopwatch.Start();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span> <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 100; i++)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>    <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> item <span style="color: #0000ff">in</span> ips)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>    {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>        <span style="color: #0000ff">string</span> s = IPLocation.IPLocation.IPLocate(<span style="color: #006080">"qqwry.dat"</span>, item);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>       <span style="color: #008000">// Console.WriteLine(s);</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span>    }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  25:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  26:</span> stopwatch.Stop();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  27:</span> Console.WriteLine(<span style="color: #006080">"IPLocation 花了{0} ms"</span>, stopwatch.ElapsedMilliseconds);</pre></div></div>
<p>性能比较结果：</p>
<p><a href="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/IPQQWry.NET_11EFE/image_6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="319" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/IPQQWry.NET_11EFE/image_thumb_2.png" width="769" border="0"></a>&nbsp;</p>
<p><a href="http://downloads.cnblogs.com/hjf1223/QQWry.NET.rar">源码和示例下载</a>。</p>
<p>阿不</p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1226174.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47946/" target="_blank">Mono这只猴子招惹了谁？</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>利用script标签实现的跨域名AJAX请求（ExtJS）</title><link>http://www.cnblogs.com/hjf1223/archive/2008/05/31/1211221.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Sat, 31 May 2008 13:38:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/05/31/1211221.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1211221.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/05/31/1211221.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1211221.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1211221.html</trackback:ping><description><![CDATA[摘要: 在AJAX应用环境中，由于安全的原因，浏览器不允许XMLHttpRequest组件请求跨域资源。在很多情况下，这个限制给我来带来的诸多不便。很多同行，研究了各种各样的解决方案： 1.通过修改document.domain和隐藏的IFrame来实现跨域请求。这种方案可能是最简单的一种跨域请求的方案，但是它同样是一种限制最大的方案。首先，它只能实现在同一个顶级域名下的跨域请求；另外，当在一个页面中还包&nbsp;&nbsp;<a href='http://www.cnblogs.com/hjf1223/archive/2008/05/31/1211221.html'>阅读全文</a><img src ="http://www.cnblogs.com/hjf1223/aggbug/1211221.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47945/" target="_blank">Firefox 3.5本月晚些时候即首次升级</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>在IE中测试调用Web Service</title><link>http://www.cnblogs.com/hjf1223/archive/2008/05/12/1194116.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Mon, 12 May 2008 14:24:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/05/12/1194116.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1194116.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/05/12/1194116.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1194116.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1194116.html</trackback:ping><description><![CDATA[<p>使用.NET 开发Web Service，有一个很方便的功能就是可以通过IE直接测试Web Service。当你的Web Service的参数都是元数据类型，那么只要你使用IE浏览Web Service就可以页面的输入框中输入必需的参数，点击调用，即可完成Web Service的测试调用。方便！</p> <p>但是，在有些情况下，虽然我们开发的Web Service都使用元数据类型的参数，为什么死活都无法直接调用测试呢？点击方法链接也只是出现SOAP消息的格式定义？原来这个问题一直都没有解决，google一下就可以找到解决办法了，只要我们在web.config中的system.web配置节点下增加这一段配置即可：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">webServices</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">protocols</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="HttpPost"</span> <span style="color: #0000ff">/&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="HttpGet"</span> <span style="color: #0000ff">/&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="HttpPostLocalhost"</span> <span style="color: #0000ff">/&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">protocols</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">webServices</span><span style="color: #0000ff">&gt;</span></pre></div></div>
<p>相关资料：<a title="http://msdn.microsoft.com/en-us/library/aa560062.aspx" href="http://msdn.microsoft.com/en-us/library/aa560062.aspx">http://msdn.microsoft.com/en-us/library/aa560062.aspx</a></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1194116.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47944/" target="_blank">Google App Engine出现故障宕机6小时</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>微软整体IT安全方案与SharePoint 2007成功案例展示&amp;mdash;&amp;mdash;ITProCity福州站邀请函</title><link>http://www.cnblogs.com/hjf1223/archive/2008/05/07/ITPro_event1.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Wed, 07 May 2008 04:37:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/05/07/ITPro_event1.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1186638.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/05/07/ITPro_event1.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1186638.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1186638.html</trackback:ping><description><![CDATA[<p>受拖发布这份邀请，有兴趣参加的朋友，请留言下你的邮箱申请，时间紧迫名额有限请赶快申请。</p> <p><i>本周六5</i><i>月10</i><i>日在福州外贸中心酒店10</i><i>楼会议室 </i>举行的福建ITPro交流活动，  <p>这是省内由微软举办的第一次IT行业专家交流会，届时我们会邀请微软最有价值专家及微软资深讲师与各位分享沟通技术热点及解决方案，希望能有机会与各位IT精英现场交流。  <p>具体安排如下：&nbsp; </p><i>如果无法正常显示，请访问：<a href="http://www.itprocity.com/event/edm/edm20080510_fuz.htm" target="_blank">http://www.itprocity.com/event/edm/edm20080510_fuz.htm</a></i>  <table cellspacing="0" cellpadding="0" width="770" bgcolor="#ffffff" border="0"> <tbody> <tr> <td colspan="2"><a href="mailto:owen@owencn.net" target="_blank"><img height="216" src="http://www.itprocity.com/event/edm/images/20080403-edm-header.png" width="770" border="0"></a></td></tr> <tr> <td style="padding-right: 72px; padding-left: 72px; padding-bottom: 4px; padding-top: 4px" width="50%" colspan="2"> <div id="title">微软整体IT安全方案与SharePoint 2007成功案例展示</div> <table width="100%"> <tbody> <tr valign="top"> <td id="left" style="padding-right: 12px"><em>活动时间：05月10日 / 14:00-17:00 / 13:30开始签到</em>  <p>信息系统给企业带来了诸多便利，越来越多的信息通过网络进行高效的传递，同时也带来了全新的挑战，即如何保护我们的系统，使它们能够在不断演变、日益增多的安全风险中安然无恙，微软有没有专门争对安全的整体方案呢？IT整体安全策略 SharePoint Server 2007是一个好平台，这大家都知道，但大部分都碰到一个问题，如何应用？能帮助企业实现什么？能给企业带来什么价值？由中国移动福建公司泉州分公司成功案例的分享，将会给我们带来一个最好的学习机会。 </p> <p><strong>日程安排</strong> <u>13:30-14:00</u>　来宾签到<br><u>14:00-14:30</u>　福建ITPRO团队介绍<br><u>14:30-15:20</u>　微软IT整体安全策略<br><u>15:20-15:40</u>　休息、交流<br><u>15:40-16:30</u>　SharePoint 2007中国移动成功案例<br><u>16:30-17:00</u>　填写反馈表/交流/Q&amp;A</p><em>联 系 人：王冬兴<br>报名电话：13313783437<br>报名邮箱：<a href="mailto:owen@owencn.net" target="_blank">owen@owencn.net</a></em>  <p><strong>ITProCity简介</strong> 　　ITProCity是一个面向IT专业人士及其团队的会员制联盟组织，面向所有IT专业人士开放，符合条件的IT专业人士和IT专业人士团队都可以成为ITProCity的会员。<br>　　ITProCity 致力构建一个社区协助平台，帮助IT专业人士及其团队沟通交流、获取知识、提升技能、实现价值；并帮助IT专业人士及其团队与主流IT厂商之间建立良好的互动关系。 </p></td> <td id="right" style="border-right: #abc7ff 1px dashed; padding-right: 12px; border-top: #abc7ff 1px dashed; padding-left: 12px; padding-bottom: 12px; border-left: #abc7ff 1px dashed; color: #325495; padding-top: 12px; border-bottom: #abc7ff 1px dashed" width="104" bgcolor="#e5ebff"><b>讲师介绍</b> <strong>宋立桓</strong>MVP <strong>雷君</strong>MVP <br><br><br><b>活动地点</b> <a href="http://www.tw128.com/UpLoadPic/hotel/2007759434055558.JPG"><img height="78" src="http://www.itprocity.com/event/edm/images/20080403-edm-maps.gif" width="104" border="0"></a> <strong>福州外贸中心酒店10楼小会议室</strong> 福州 鼓楼区 五四路73号</td></tr></tbody></table><br></td></tr> <tr> <td style="padding-right: 72px; padding-left: 72px; padding-bottom: 4px; padding-top: 4px" colspan="2"> <div align="right">ITProCity团队<br>福建ITPRO团队<br>2008年05月<br> <hr color="#cccccc" noshade size="1"> </div></td></tr></tbody></table><img src ="http://www.cnblogs.com/hjf1223/aggbug/1186638.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47943/" target="_blank">消息称Facebook今年营收将达5.5亿美元</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>深入ASP.NET数据绑定（下）&amp;mdash;&amp;mdash;多样的绑定方式</title><link>http://www.cnblogs.com/hjf1223/archive/2008/05/05/digging_into_binding_expression_3.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Mon, 05 May 2008 14:32:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/05/05/digging_into_binding_expression_3.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1183933.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/05/05/digging_into_binding_expression_3.html#Feedback</comments><slash:comments>20</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1183933.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1183933.html</trackback:ping><description><![CDATA[摘要: 在这个系列的上篇中介绍了数据绑定语法的原理以及.NET中如何实现单向绑定，中篇我们简单的介绍了ASP.NET 2.0 中新增的Bind语法配合DataSourceControl来实现数据的自动双向绑定。这两部分的内容相对动态抽象并且不常接触，没有很好的源代码支持很难解释清楚，要想真正弄清它们的内部原理，还需要大家亲自动手去反编译分析动态编译的程序集。 在了解了数据绑定语法的原理后，我还想来谈谈我中&nbsp;&nbsp;<a href='http://www.cnblogs.com/hjf1223/archive/2008/05/05/digging_into_binding_expression_3.html'>阅读全文</a><img src ="http://www.cnblogs.com/hjf1223/aggbug/1183933.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47937/" target="_blank">微软8月25日开始通过WSUS推送IE8</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>深入ASP.NET数据绑定（中）&amp;mdash;&amp;mdash;数据双向绑定机理</title><link>http://www.cnblogs.com/hjf1223/archive/2008/05/04/digging_into_binding_expression_2.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Sun, 04 May 2008 14:15:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/05/04/digging_into_binding_expression_2.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1182399.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/05/04/digging_into_binding_expression_2.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1182399.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1182399.html</trackback:ping><description><![CDATA[<p>在上一篇《<a href="http://www.cnblogs.com/hjf1223/archive/2008/05/03/digging_into_binding_expression_1.html">深入ASP.NET数据绑定（上）</a>》中，我们分析了在.NET中的数据绑定语法的一些内部机理。简单说来就是ASP.NET在运行时为我们完成了页面的动态编译，并解析页面的各种服务器端代码，包括数据绑定语法。而数据绑定的语法虽是一些&lt;%# %&gt;代码块，在生成的代码中，仍然使用了服务器端控件以及在DataBinding事件调用DataBinder.Eval方法来完成数据的绑定工作。所有的数据绑定模板控件都使用了这样的机制来进行数据的单向绑定，在.NET 2.0中新增了双向的数据绑定方式，主要用在GridView,DetailsView,FormView等数据容器控件中，结合DataSourceControl就可以非常轻松的完成数据的更新和提交工作，而不需要我们手工去遍历输入控件的值。那在这样的双向数据绑定中，ASP.NET又是做了哪些工作，来为我们透明输入控件与字段的取值与对应关系，让我们可以在DataSouceControl中方便得到数据项修改前的值和修改后的值？下面就让我们一起来从一段页面代码开始吧：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:DetailsDataSouce</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="DetailsDataSouce1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:DetailsDataSouce</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:DetailsView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="detailsView"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">DefaultMode</span><span style="color: #0000ff">="Edit"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="DetailsDataSouce1"</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Fields</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>             <span style="color: #0000ff">&lt;</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>                 电流:<span style="color: #0000ff">&lt;/</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>             <span style="color: #0000ff">&lt;</span><span style="color: #800000">EditItemTemplate</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>                 <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="textBox1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">='&lt;%# Bind("[电流{a}]") %&gt;'</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>             <span style="color: #0000ff">&lt;/</span><span style="color: #800000">EditItemTemplate</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>         <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Fields</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:DetailsView</span><span style="color: #0000ff">&gt;</span></pre></div></div>
<p>在一个页面中，定义了如上的一个DetailsView控件，为这个控件指定了ID为DetailsDataSource1的DataSouceControl控件，这个控件是我们自己定义的一个DataSourceControl，它返回的数据字段包括："ID"，"电流{a}"，"电压(v)"，"备注'"，"名称]"。我并没有设置DetailsView的<span style="color: red">AutoGenerateRows</span>属性的值，默认情况下，它是为我们自动的生成这些字段的对应的数据显示和输入控件。除此之外，我们还另外添加了一个数据模板字段，在这个模板中指定了编辑模板。在编辑模板中我使用了&lt;%# Bind("")%&gt;这样的语法，将textBox1与"[电流{a}]"字段双向绑定起来。</p>
<p><img alt="Thumbsup" src="http://www.cybergifs.com/faces/thumbsup2.gif"><font color="#ff0000">为什么这里的字段都有一些特殊呢？因为我原先的意图是除了分析绑定语法以外，还要测试哪些特殊字符无法使用数据绑定语法来绑定数据的。这个在下篇文章中会具体介绍。</font></p>
<p><img alt="Thumbsup" src="http://www.cybergifs.com/faces/thumbsup2.gif"><font color="#ff0000">Bind与Eval不一样，这样的Bind并不Page或TemplateControl的一个方法，事实上我们应该把它当成一个关键字来看待，因为在ASP.NET的双向数据绑定当中，并没有这样的一个函数存在，它的存在是只是告诉ASP.NET动态编译页面类时，将这个语法编译成一定的代码格式，并生成一些函数代理来达到双向数据交流的目的。</font></p>
<p>那么这一段代码，动态编译生成的服务器代码又是如何的呢？让我们反编译动态程序集，里面会找到用于创建DetailsView的__BuildControldetailsView的私有方法，在这里会调用到一些其它内部方法，我们不要让这些方法来干扰我们的视线，直接找到创建如上模板字段的方法：</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> [DebuggerNonUserCode]</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">private</span> TemplateField __BuildControl__control5()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     TemplateField field = <span style="color: #0000ff">new</span> TemplateField();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     field.HeaderTemplate = <span style="color: #0000ff">new</span> CompiledTemplateBuilder(<span style="color: #0000ff">new</span> BuildTemplateMethod(<span style="color: #0000ff">this</span>.__BuildControl__control6));</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     field.EditItemTemplate = <span style="color: #0000ff">new</span> CompiledBindableTemplateBuilder(<span style="color: #0000ff">new</span> BuildTemplateMethod(<span style="color: #0000ff">this</span>.__BuildControl__control7), <span style="color: #0000ff">new</span> ExtractTemplateValuesMethod(<span style="color: #0000ff">this</span>.__ExtractValues__control7));</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     <span style="color: #0000ff">return</span> field;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span> }</pre></div></div>
<p>这里首先把this.__BuildControl__control6作为一个代理函数，用于创建头部模板的内容，也就是如上的“电流：”字段标题。然后才是创建EditItemTemplate，这个模板又被一些的中介模板所代替，我们只需要来关心this.__BuildControl__control7和__ExtractValues__control7即可。__BuildControl__control7是为了编辑数据字段时，将数据字段的值显示在输入控件中（输入控件的初始化，即字段值绑定到输入控件中）；而__ExtractValues__control7则是在提交数据时，要找出这个模板内所有的双向绑定字段，将这些字段的值以绑定字段名为Key，以输入控件的值为Value添加了IOrderedDictionary字典中。DetailsView等数据绑定控件调用这些委托代理来收集所有的被双向绑定的字段的最新的值。下面分别是两段函数的代码片段：</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> [DebuggerNonUserCode]</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">private</span> TextBox __BuildControl__control8()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     TextBox box = <span style="color: #0000ff">new</span> TextBox();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     box.TemplateControl = <span style="color: #0000ff">this</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     box.ApplyStyleSheetSkin(<span style="color: #0000ff">this</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     box.ID = <span style="color: #006080">"textBox1"</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     box.DataBinding += <span style="color: #0000ff">new</span> EventHandler(<span style="color: #0000ff">this</span>.__DataBinding__control8);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">return</span> box;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> __DataBinding__control8(<span style="color: #0000ff">object</span> sender, EventArgs e)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>     TextBox box = (TextBox) sender;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>     IDataItemContainer bindingContainer = (IDataItemContainer) box.BindingContainer;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>     <span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span>.Page.GetDataItem() != <span style="color: #0000ff">null</span>)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>         box.Text = Convert.ToString(<span style="color: #0000ff">base</span>.Eval(<span style="color: #006080">"[电流{a}]"</span>), CultureInfo.CurrentCulture);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span> }</pre></div></div>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> [DebuggerNonUserCode]</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> IOrderedDictionary __ExtractValues__control7(Control __container)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     TextBox box = (TextBox) __container.FindControl(<span style="color: #006080">"textBox1"</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     OrderedDictionary dictionary = <span style="color: #0000ff">new</span> OrderedDictionary();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     <span style="color: #0000ff">if</span> (box != <span style="color: #0000ff">null</span>)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         dictionary[<span style="color: #006080">"[电流{a}]"</span>] = box.Text;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     <span style="color: #0000ff">return</span> dictionary;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span> }</pre></div></div>
<p>由上面的代码片段可以了解到，ASP.NET动态编译器是将Bind语法拆分为两部分：绑定输出和读取输入控件值。绑定输出部分与前篇介绍的机制是完全一样的，并且也是调用DataBinder.Eval方法来绑定数据；而读取输入控件值则是会根据页面上控件的类型，以及绑定的控件属性名称，生成一段强类型的控件属性读取代码，并将控件的值保存到dictionay中返回出去。而它全然不知，容器控件是如何将这些值合并起来传给对应的DataSouceControl控件的。</p>
<p><img alt="Thumbsup" src="http://www.cybergifs.com/faces/thumbsup2.gif"><font color="#ff0000">关于数据容器控件而何与DataSouceControl协同工作，并不是我们这里要分析的重点。但是我们可以简单的描述一下工作流程，以DetailsView的数据更新为例：大家通过反编译DetailsView的源码，会找到名称为HandleUpdate的私有方法，在这个方法里面会去处理数据项更新前的值(至于在Web环境中如何保存更新前的值，就需要靠ViewState的强大功能了)，和更新后的值(通过ExtractRowValues函数调用类似上面生成的__ExtractValues__control7代理函数来收集所有双向绑定字段的值存到NewValues里面)，并将他们分别保存在两个不同的IOrderedDictionary对象（OldValues，NewValues）中。然后将调用对应的DataSouceView的Update方法，传入原字段值和新字段值和一些必须的参数，即可由我们通过重写DataSourceView的方法来得到所有需要更新字段的原始值和新值，并可以对比比较哪些字段值是否发生了变化。NBearDataSource控件就是利用了这样的机制来直接重DataSourceControl和DataSourceView来达到数据的全自动修改和添加方案的。</font></p>
<p>这里还有一点不得不说，在GridView,DetailsView，并不一定需要使用&lt;%# Bind("")%&gt;语法来实现数据的双向绑定，他们的字段双向绑定可以通过BoundField及它的子控件代替模板控件的绑定语法，一样可以达到双向绑定的目的，简单但没有模板来得灵活。而在存取不同版本的字段值也是类似的机制。</p>
<p>由于这部分涉及到的都是动态和内部代码，如果没有亲自去阅读这些代码，估计还是很难理解。最后我们再来简单总结一下：ASP.NET在模板中双向绑定字段，是通过&lt;%# Bind() %&gt;这样的语法，但是Bind我们更应该把它理解为是一个关键字，而不是一个函数。因为在ASP.NET的控件中，并没有存在这个函数。ASP.NET运行时在编译页面代码时，会把Bind关键字的代码当成两部分来编译：一部分是单向绑定代码；另一部分而是读取对应输入控件的绑定属性，以绑定字段名为Key，添加到IOrderedDictionary中收集返回给数据容器控件（GridView,DetailsView,FormView）等，让它们处理。</p>
<p>总体来说，ASP.NET 2.0的双向绑定机制给我们在提交数据时带来了极大的方便，尽管有些人很排斥DataSourceControl的模式，但是我们不可否认合理应用会大大提高我们的开发效率。希望通过这两篇的介绍，我们能对ASP.NET数据绑定机制有更多的认识。在下一篇的文章中，我们将会介绍一些关于数据绑定方式，性能，以及对字段名的局限性等相关主题。</p>
<p><a href="http://www.cnblogs.com/Files/hjf1223/ColumnName.rar">附上示例工程</a>，本文分析面页是Default3.aspx和App_Web_ryn6wtvv.dll程序集。</p>
<p><font color="#ff0000">系列导航:</font></p>
<p><a href="http://www.cnblogs.com/hjf1223/archive/2008/05/03/digging_into_binding_expression_1.html"><font color="#ff0000">深入ASP.NET数据绑定（上）</font></a></p>
<p><a href="http://www.cnblogs.com/hjf1223/archive/2008/05/05/digging_into_binding_expression_3.html"><font color="#ff0000">深入ASP.NET数据绑定（下）——多样的绑定方式</font></a></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1182399.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47935/" target="_blank">暴风称新旧版更换完毕 总计超4000万用户换装</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>深入ASP.NET数据绑定（上）</title><link>http://www.cnblogs.com/hjf1223/archive/2008/05/03/digging_into_binding_expression_1.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Sat, 03 May 2008 15:05:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/05/03/digging_into_binding_expression_1.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1180962.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/05/03/digging_into_binding_expression_1.html#Feedback</comments><slash:comments>33</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1180962.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1180962.html</trackback:ping><description><![CDATA[摘要: 在ASP.NET我们在使用Repeater，DetailsView，FormView，GridView等数据绑定模板时，都会使用<%# Eval("字段名") %>或<%# Bind("字段名") %>这样的语法来单向或双向绑定数据。但是我们却很少去了解，在这些语法的背后，ASP.NET究竟都做了哪些事情来方便我们使用这样的语法来绑定数据。究竟解析这样的语法是在编译时，还是运行时？如果没有深入去了解，我们肯定不得而知。这个简短的系列文章就是带我们大家一起去深入探究一下ASP.NET绑定语法的内部机理，以让我们更加全面的认识和运用它。&nbsp;&nbsp;<a href='http://www.cnblogs.com/hjf1223/archive/2008/05/03/digging_into_binding_expression_1.html'>阅读全文</a><img src ="http://www.cnblogs.com/hjf1223/aggbug/1180962.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47934/" target="_blank">3.5版既出 Firefox面临新挑战</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>LumaQQ.NET Preview 3 发布&amp;mdash;&amp;mdash;新增群信息功能</title><link>http://www.cnblogs.com/hjf1223/archive/2008/04/22/lumaqq_net_preview3.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Tue, 22 Apr 2008 14:15:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/04/22/lumaqq_net_preview3.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1166331.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/04/22/lumaqq_net_preview3.html#Feedback</comments><slash:comments>55</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1166331.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1166331.html</trackback:ping><description><![CDATA[<p><font color="#ff0000">版权声明：该开源开发包，是基于LumaQQ的基于等价移植到.NET平台下，开发者不直接参与QQ协议的分析工作，移植到.NET平台纯粹是为了方便广大.NET开发者学习和研究之用，并且没有产生任何直接的经济效益，并且纯粹是个人的技术学习研究行为，与本人所在单位没有任何关系。此开发包的用户在使用过程产生的效益和涉及的法律责任与本人没有直接关系。如果影响到您或您的公司利益，敬请谅解并且与我联系，本人会第一时间作出处理。本系列章首发且单发于博客园，由于各种原因不欢迎转载本系列文章，如果您转载了该系列文章请自行承担责任并且转载完整版本，包括版权声明。</font></p> <p>首先要向所有关心LumaQQ.NET发展的朋友们道个歉，因为距上一次版本更新已经过去了一个多月的时间了，新版本一直迟迟都没有发布。在这段时间里，由于一些个人原因，没有时间和精力投入到新版本的开发当中来，让大家失望了。最近很多人都在问，LumaQQ.NET希望做得什么程度。我目前的定位是：以Lumaqq2005的协议为蓝本，基本能做到简单的文本信息收发功能即可，不打算去分析更新的协议，也不找算做到能基本代替官方QQ的程度，因为我们是定位在机器人开发包的级别。如果有让您失望，还请谅解。关于更详细的开发计划请参考：<a href="http://space.cnblogs.com/group/topic/1717/">关于LumaQQ.NET未来开发计划</a></p> <p>在Preview 3当中，我们主要增加了群消息的功能（但不包括群管理功能），还修复和完善了之前存在的一些不足和BUG，下面就来简单了解下：</p> <h4>框架完善部分</h4> <ol> <li>使用了新的ByteBuffer，可以解决可能存在的内存使用不合理的问题（感谢<a href="http://space.cnblogs.com/22667/">Red_angelX</a>的提醒和提供这么好的一个类）  <li>完善信息发送接口,可以收发长信息（感谢<a href="http://space.cnblogs.com/lersh/">蓝色的风之精灵</a>的贡献）  <ul> <li>关于如何实现收发长信息可以参考<a href="http://space.cnblogs.com/lersh/">蓝色的风之精灵</a>的两篇文章<a href="http://www.cnblogs.com/lersh/archive/2008/04/22/1165451.html">修改LumaQQ.NET，使其支持长消息发送</a>和<a href="http://www.cnblogs.com/lersh/archive/2008/04/22/1165919.html">使LumaQQ.NET支持接收长消息</a></li></ul> <li>可以解析默认表情(解析成[face0.gif]等格式,由用户去替换)和自定义表情(文件名) （感谢<a href="http://space.cnblogs.com/lersh/">蓝色的风之精灵</a>的贡献）  <ul> <li>关于解析表情同样请参考<a href="http://space.cnblogs.com/lersh/">蓝色的风之精灵</a>的文章<a href="http://www.cnblogs.com/lersh/archive/2008/04/21/1163565.html">关于转换QQ消息中系统表情，自定义表情和截图的函数</a>。与之不同的是，我把默认表情都解析成[face{0}.gif]的格式，大家可以根据需要再去替换。</li></ul> <li>修复了一些已知的bug，包括之前的天气预报日期问题和QQ注销后程序不退出会出错的问题等。</li></ol> <h4>新增功能部分，主要新功能群信息的功能</h4> <ol> <li>得到我加入的群列表。  <ul> <li>这个功能需要使用好友管理的读取好友列表的功能，在返回的好友列表中有两种好：普通好友和群好友。大家只要根据定义的类型来判断就可以得到所加入的群列表，如：<span style="color: blue">if</span>(friend.Type == <span style="color: #2b91af">FriendType</span>.IS_CLUSTER)<a href="http://11011.net/software/vspaste"></a></li></ul> <li>接收群消息和群通知的功能  <ul> <li>这个功能分为几个事件，这些事件的InPacket事件参数类型都为ReceiveIMPacket，但是事件不同，里面的属性字段使用不同，同样的，所有的群操作命回复事件包都是ClusterCommandReplyPacket，但是根据事件不同，这个对象的属性使用不同。请大家仔细查阅ClusterCommandReplyPacket的注释说明。  <ul> <li>ReceiveClusterIM：接收到群消息事件  <li>AddedToCluster:被加入到群通知  <li>RemovedFromCluster:被从某个群中移动的通知  <li>ApprovedJoinCluster:群管理员同意我加入群的通知  <li>RejectJoinCluster：群管理员拒绝的加入群的通知  <li>HasRequestedJoinCluster:有人请求加入群的通知</li></ul></li></ul> <li>请求加入群功能，这个功能通过JoinCluster接口发送请求，如果返回结果提示需要发送身份验证，则调用RequestJoinCluster来发送验证信息。加入结果则以系统通知（上面的事件）的形式返回。  <li>根据群ID查找群，通过SearchClusterById发送查找群请求。  <li>退出群，通过调用ExitCluster请求退出群。  <li>发送群信息功能，暂不能分包发送长信息。  <li>修改群名片  <li>刷新群内组织架构  <li>得到单个成员和全部群名片信息  <li>得到群资料，群成员列表（QQ号码）  <li>得到在线成员  <li>得到群成员详细信息</li></ol> <p>以上功能测试基本正常，如果有任何问题或疑问请通过<a href="http://space.cnblogs.com/group/lumaQQ_net">LumaQQ.NET</a>小组交流讨论，同时大家也可以加入LumaQQ.NET QQ群讨论，号码是：22858783 谢谢！</p> <p>另外，在这里要特别感谢<a href="http://space.cnblogs.com/lersh/">蓝色的风之精灵</a>的热心和贡献，解决了一些疑难问题，希望大家再接再厉一起来完善LumaQQ.NET。 </p> <p><a href="http://www.cnblogs.com/Files/hjf1223/LumaQQ.NET.rar">文档和源码下载</a></p> <p><font color="#ff0000">更新：增加了for vs 2005的Preview3。&nbsp; 04/24/2008</font></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1166331.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47930/" target="_blank">Bing首页将显示各国美景 顺推Silverlight</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>不定时的间隔线程和线程排队执行(LumaQQ.NET异步线程处理)</title><link>http://www.cnblogs.com/hjf1223/archive/2008/04/17/1156596.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 17 Apr 2008 11:18:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/04/17/1156596.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1156596.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/04/17/1156596.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1156596.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1156596.html</trackback:ping><description><![CDATA[<p>在我的这篇文章《<a href="http://www.cnblogs.com/hjf1223/archive/2008/03/06/Framework_Timer.html">.NET Framework中的计时器对象</a>》中，讨论了几种.NET Framework定时器异同之处，以及使用场合。我当时的初忠也是在为<a href="http://www.cnblogs.com/hjf1223/archive/2008/03/11/qq_net.html">LumaQQ.NET</a>寻找一种最合理的线程定时执行和线程排队的方案。因为在LumaQQ中，有需要定时执行的线程，比如发送KeepLive包；有需要不同间隔时间，间隔时间是动态的且不应该是“可重入”（前一个执行还没有完成，又再次进行执行定时任务），比如重发包；有需要在一个独立线程上不定期执行的任务，比如收到包后的事件处理（收到数据包后，程序主线程需要继续去监听数据，而不能在主线程上去进行包的处理工作，这样如果事件代理的执行时间很长的话，主线程的执行周期被占用了，而造成无法及时接收和发送数据包）。在这三种情况下，直接使用Timer组件肯定无法完全满足我们的要求。</p> <p>通过分析Timer组件，我们就很容易发现，他们都是通过<span style="color: #2b91af">ThreadPool</span>这个类的功能来实现定时器的功能。ThreadPool类，提供了对当前进程内的后台线程统一管理，集中调配和资源重用的线程池实现。利用ThreadPool可以实现任务的延迟处理，I/0 异常操作，线程间的互斥执行，定时任务等功能。</p> <p>ThreadPool提供了一系列管理和维护线程池的接口。在LumaQQ.NET中，我需要的功能就是利用：QueueUserWorkItem 和RegisterWaitForSingleObject 这两个接口来实现的。</p> <p>QueueUserWorkItem :让我们可以注册一个排队的异步任务，等到线程池有剩余的线程资源时去异步执行任务。</p> <p>RegisterWaitForSingleObject :让我们可以注册一个等待信号就绪的异步任务，等到该线程等待的信号就绪后异步执行该任务。这个接口等待信号是一个WaitHandle对象，同时还可以指定等待超时（间隔时间），而通过设置executeOnlyOnce参数的值可以指定是否重复执行该任务。</p> <p>了解了ThreadPool的基本情况后，我们就可以来设计我们的异步线程执行框架。首先对异步任务和间隔任务，我们分别定义了两个接口<span style="color: #2b91af">ICallable</span>和<span style="color: #2b91af">IRunable</span>来描述：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 98.7%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 390px; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #008000">/// 可以被提交到线程池异步处理的接口</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> ICallable</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     <span style="color: #008000">/// 是否已经在运行</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     <span style="color: #008000">/// &lt;value&gt;&lt;/value&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     <span style="color: #0000ff">bool</span> IsRunning { get; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>     <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>     <span style="color: #008000">/// WaitCallback回调</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>     <span style="color: #008000">/// &lt;param name="state"&gt;The state.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>     <span style="color: #0000ff">void</span> Call(<span style="color: #0000ff">object</span> state);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span> <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span> <span style="color: #008000">/// 可以被提交到线程池定时运行的接口</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span> <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span> <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IRunable : IDisposable</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  25:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  26:</span>     <span style="color: #008000">/// &lt;summary&gt;是否已经在运行</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  27:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  28:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  29:</span>     <span style="color: #008000">/// &lt;value&gt;&lt;/value&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  30:</span>     <span style="color: #0000ff">bool</span> IsRunning { get; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  31:</span>     <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  32:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  33:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  34:</span>     <span style="color: #008000">/// &lt;param name="state"&gt;The state.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  35:</span>     <span style="color: #008000">/// &lt;param name="timedOut"&gt;if set to &lt;c&gt;true&lt;/c&gt; [timed out].&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  36:</span>     <span style="color: #0000ff">void</span> Run(<span style="color: #0000ff">object</span> state, <span style="color: #0000ff">bool</span> timedOut);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  37:</span>     <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  38:</span>     <span style="color: #008000">/// 注册在线程池后的信号变量</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  39:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  40:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  41:</span>     <span style="color: #008000">/// &lt;value&gt;&lt;/value&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  42:</span>     WaitHandle WaitHandler { get; set; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  43:</span>     <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  44:</span>     <span style="color: #008000">/// 注册后的对象</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  45:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  46:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  47:</span>     <span style="color: #008000">/// &lt;value&gt;&lt;/value&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  48:</span>     RegisteredWaitHandle RegisterdHandler { get; set; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  49:</span> }</pre></div></div>
<p>之后，我们需要定义一个任务注册类，来管理异步任务的注册的提交工作，这个类我将它命名为：<span style="color: #2b91af">ThreadExcutor</span></p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 98.83%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 343px; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #008000">/// 利用线程池来异步执行线程</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ThreadExcutor</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     <span style="color: #008000">/// &lt;summary&gt;提交一个线程等待执行</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     <span style="color: #008000">/// &lt;param name="callable"&gt;The callable.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     <span style="color: #008000">/// &lt;param name="state"&gt;The state.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Submit(ICallable callable, <span style="color: #0000ff">object</span> state)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         <span style="color: #0000ff">if</span> (!callable.IsRunning)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>             ThreadPool.QueueUserWorkItem(<span style="color: #0000ff">new</span> WaitCallback(callable.Call), state);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>     <span style="color: #008000">/// &lt;summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>     <span style="color: #008000">/// 注册一个轮循线程</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>     <span style="color: #008000">///     &lt;remark&gt;abu 2008-03-07 &lt;/remark&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>     <span style="color: #008000">/// &lt;/summary&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>     <span style="color: #008000">/// &lt;param name="runnable"&gt;The runnable.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span>     <span style="color: #008000">/// &lt;param name="state"&gt;The state.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  25:</span>     <span style="color: #008000">/// &lt;param name="interval"&gt;The interval.&lt;/param&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  26:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> RegisterIntervalObject(IRunable runnable, <span style="color: #0000ff">object</span> state, <span style="color: #0000ff">long</span> interval, <span style="color: #0000ff">bool</span> onlyOnce)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  27:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  28:</span>         <span style="color: #008000">// if (runnable.RegisterdHandler == null)</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  29:</span>         <span style="color: #008000">// {</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  30:</span>         runnable.WaitHandler = <span style="color: #0000ff">new</span> AutoResetEvent(<span style="color: #0000ff">false</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  31:</span>         runnable.RegisterdHandler = ThreadPool.RegisterWaitForSingleObject(runnable.WaitHandler, <span style="color: #0000ff">new</span> WaitOrTimerCallback(runnable.Run), state, interval, onlyOnce);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  32:</span>         <span style="color: #008000">// }</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  33:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  34:</span> }</pre></div></div>
<p>实际上这个类，只是将传入ICallable和IRunable对象，注册到线程池当中来，而运行时机则由线程池去管理和分配。接下来就是实际的任务设计了，在LumQQ.NET中目前有三个这种的任务：</p>
<p>PacketIncomeTrigger：异步处理输入包。只有等到有收到数据后，才提交这个任务，在后台线程中去处理QQ事件。一次处理会全部处理所有已收到的输入包，处理完后退出。当包处理线程正在运行时，试图注册相同任务将自动不会被注册。</p>
<p>KeepAliveTrigger：定时执行发送在线包的任务，它实现的就是Timer组件的功能。</p>
<p>ResendTrigger：这是一个不定时执行的间隔线程。重复发送包，保证每一次重得发送包都是顺序执行的，而不希望同时可能执行多个重复发送包线程，而且下一次的执行时间也是动态的。要实现这个功能我们只需要在注册等待线程时指定合适的超时时间和executeOnlyOnce为true(只执行一次)，等到任务执行结束后，再重新注册一次定时线程。这样就可以完善解决不定时的间隔线程问题了。</p>
<p>更多详细的功能实现请参考LumaQQ.NET中的相关代码。</p>
<p><a href="http://hjf1223.cnblogs.com">阿不</a></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1156596.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47929/" target="_blank">Gmail 的标签马上就会支持拖拽操作了</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>Http环境下的保持连接方式</title><link>http://www.cnblogs.com/hjf1223/archive/2008/04/10/http_keepConnecting.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Thu, 10 Apr 2008 12:11:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/04/10/http_keepConnecting.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1147365.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/04/10/http_keepConnecting.html#Feedback</comments><slash:comments>35</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1147365.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1147365.html</trackback:ping><description><![CDATA[<p>Http环境本身是一种无连接状态的架构，在这种架构下服务器只能是被动的接受客户端的请求，返回结果，而无法主动的给客户端发送数据。而在很多需要实时数据交互（比如Web IM)的场景中，我们却希望能及时得到服务器给我们返回的数据。此时，一种最为普遍的做法是：在客户端用定时器，定时去请求服务器的服务，来得到最新数据。而这样一来，很多时候却是在做无用功，频繁的请求也会无端的增加服务器和客户端在请求Web服务上的消耗。那么是否有一种更好的办法，既可以及时得到服务器的返回，同时又可以减少做无用功，以及频繁请求带来的性能问题呢？</p> <p>记得前不久，在园子里有这样的一篇文章，介绍了几种WEB环境定时刷新数据的机制。其中就有提到google gmail的一种比较巧妙的做法，现在记不得当时是怎么理解这种做法了，只记得有“保持长连接”的基本做法。（当然现在也找不到这篇文章了，希望了解的朋友能提醒一下）。今天由于架构方案的需要，再来仔细思考连接保持方案，以及参考gmail的请求行为，总结了一下，应该是这样的：客户端一直保持一个与服务器的连接，这个连接一直保持着对服务器的请求动作，直到服务器发现有数据后给它返回后，才结束返回这一次请求。客户端在接收到请求返回后，在处理这些返回之前，又向服务器发送了一次连接请求，直到下一次有数据返回。不可避免的有一种情况，就是如果服务器长时间没有需要给客户端发送数据的话，那么可以就会造成请求失败（超时或其它原因）。对于这种情况的处理也是一样的，在错误的回调事件中重新发送一次请求连接。这样就可以模拟保持连接状态了。</p> <p>用伪代码来描述一下思路吧：</p> <p>客户端脚本：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">function</span> Request()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     Ajax.Request(url,OnSuccessed,OnFailed);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> <span style="color: #0000ff">function</span> OnSuccessed(response)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     <span style="color: #008000">//重新发送一次请求</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     Request();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>      <span style="color: #008000">//处理返回数据</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span> }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span> <span style="color: #0000ff">function</span> OnFailed()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>     <span style="color: #008000">//错误（超时）重新请求</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>     Request();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span> }</pre></div></div>
<p>Web服务：</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> IMService : IHttpHandler</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsReusable{<span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ProcessRequest(HttpContext context)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         <span style="color: #008000">//读取最新数据</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>         <span style="color: #0000ff">while</span>(<span style="color: #0000ff">true</span>)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>             <span style="color: #0000ff">string</span> message = GetMessage();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>             <span style="color: #0000ff">if</span>(!<span style="color: #0000ff">string</span>.IsNullOrEmpty(message))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>             {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>                 context.Response.Write(message);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>                 <span style="color: #0000ff">break</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>             }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>             Thread.Sleep(500);<span style="color: #008000">//等待一段时间再重新读取。</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>     <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> GetMessage()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>         <span style="color: #008000">//取得最新数据</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span> }</pre></div></div>
<p>这种方案的好处有：客户端可以第一时间得到服务器需要给客户端发送的数据（<font color="#ff0000">而至于Web服务怎么知道要给客户端发送数据，也就是服务器的轮循设计，则是另一个需要考虑的方案</font>）；可以减化客户端逻辑，无需要创建和释放定时器，并减小由此产生的对客户端性能的损失；减少去服务器的请求次数，减少做无用功，节约节省带宽和减少服务器资源需要处理的连接请求。</p>
<p>相信在此之前，已经有很多人在使用这种方案了。欢迎大家就此方案发表自己的见解。</p>
<p><font color="#ff0000">补充：服务器部分的设计，除了使用轮循外，也可以考虑使用资源互斥访问的方式来设计，这样做可以获得更佳性能，更高实时性，具体的方案应当根据实际情况来考虑。相关的设计可以参考</font><a href="http://cathsfz.cnblogs.com/"><font color="#ff0000">Cat Chen</font></a><font color="#ff0000">的文章《</font><a href="http://www.cnblogs.com/cathsfz/archive/2008/03/08/1096654.html"><font color="#ff0000">使用 .NET 实现 Ajax 长连接 (Part 2 - Mutex Wait &amp; Signal)</font></a><font color="#ff0000">》</font></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1147365.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47928/" target="_blank">Windows 7 触摸功能是摆设 无厂商支持价值不大</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>首次当选微软MVP</title><link>http://www.cnblogs.com/hjf1223/archive/2008/04/01/1133363.html</link><dc:creator>阿不</dc:creator><author>阿不</author><pubDate>Tue, 01 Apr 2008 11:22:00 GMT</pubDate><guid>http://www.cnblogs.com/hjf1223/archive/2008/04/01/1133363.html</guid><wfw:comment>http://www.cnblogs.com/hjf1223/comments/1133363.html</wfw:comment><comments>http://www.cnblogs.com/hjf1223/archive/2008/04/01/1133363.html#Feedback</comments><slash:comments>74</slash:comments><wfw:commentRss>http://www.cnblogs.com/hjf1223/comments/commentRss/1133363.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/hjf1223/services/trackbacks/1133363.html</trackback:ping><description><![CDATA[<p>今天是愚人节，还因为一些烦心的事，在沉闷了一天后，就在即将结束这一天的工作时，突然看到微软MVP项目组发来的MVP获奖邮件。眼前一亮，打开邮件在确定事情的准确性后。还没来得及仔细阅读邮件的内容，就赶快与一位不是很重要的人分享我的快乐，呵呵。<img alt="smile_regular" src="http://spaces.live.com/rte/emoticons/smile_regular.gif"></p> <p>我个人挺看重MVP这个荣誉的，因为我刚刚入门的时，就从广大的MVP专家那里学到了很多东西，那时就梦想有朝一日我也能成为这MVPs中的一员，也能为.NET社区做出自己的贡献。一直以来，我都在不屑努力的提高着自己，也慢慢看到了自己的进步，在工作中，我的努力慢慢得到了认可。而当选MVP，则是社区力量对我最大的鼓励。技术的追求永无止境，毕业即将4年（学习使用.NET3年半的时间），4年只是我的一个开始。接下来技术生涯中，我还希望能保持对技术的热情，不断追求和探索，力争在技术上取得更大的进步。</p> <p>在这里，还不得不感谢<a href="http://www.cnblogs.com/">博客园</a>，感谢<a href="http://dudu.cnblogs.com/">dudu</a>，感谢园子里所有帮助和关心过我的朋友们。大家的支持和鼓励是我不断取得进步不可缺少的力量，我也将尽自己最大的努力，在以后的日子里做出更多力所能及的贡献。同时也祝贺本次当选的其他MVP们，以后有机会一定向大家多多学习。</p> <p>PS.今天是愚人节,希望不是被微软给愚了...<img alt="smile_sad" src="http://spaces.live.com/rte/emoticons/smile_sad.gif"></p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/MVP_1106D/MVP_Horizontal_BlueOnly_2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="78" alt="MVP_Horizontal_BlueOnly" src="http://www.cnblogs.com/images/cnblogs_com/hjf1223/WindowsLiveWriter/MVP_1106D/MVP_Horizontal_BlueOnly_thumb.png" width="186" border="0"></a></p><img src ="http://www.cnblogs.com/hjf1223/aggbug/1133363.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47927/" target="_blank">虚拟货币上了"紧箍咒" 新规将限制Q币发行</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item></channel></rss>