David's profileprowyh's spaceBlogLists Tools Help

Blog


    December 28

    Visual Studio .NET Debugger的一个问题及其解决

    实际上,这本来不算一个问题,但如果不知道原因及解决办法的话,就足以让人frustrated。
     
    在Visual Studio .NET 2005中新建一个ASP.NET项目,假设使用默认站点,即http://localhost,则Visual Studio .NET自动在根目录下生成两个初始文件:Default.aspx及Default.aspx.cs。此时,按F5进行调试运行,则弹出如下对话框:
     
     
    弹出此对话框的原因是因为ASP.NET项目的根目录下没有Web.config文件,从而没有启用调试功能造成的,解决办法是打开IIS管理器,编辑ASP.NET配置,如下图所示:
     
     
    或手工编辑Web.config文件:
     
    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <compilation debug="true" />
        </system.web>
    </configuration>
     
    这个最小的Web.config文件启用了Debug功能,就可以避免上面的问题。
     
    但这并不是本文所要讲述的问题(虽然也是一个问题)。解决了这个小问题之后,更大的问题是下面的对话框:
     
     
    Google了一下,发现这是一个普遍问题,后来在Visual Studio .NET的帮助文件中找到了解决办法:
     
     
    如图中红线标记所示,启用“集成Windows身份验证”即可。
     
    但为什么需要启用“集成Windows身份验证”呢?后来在Microsoft的KB 937523中找到了这样一段话:
     
    When the client tries to automatically attach the debugger in an ASP.NET 2.0 application, the client sends a HTTP request that contains the DEBUG verb. This HTTP request is used to verify that the process of the application is running and to select the correct process to attach. This HTTP request must be authenticated by using Windows Authentication.
     
    最后在Min Kwan Park's bLog中发现有如此多与Visual Studio Debugger有关的问题,基本都是Unable to start debugging on the web server。
     
    December 06

    Hosting WebBrowser:一个令人沮丧的问题

    一个简单的在Windows Form中嵌入WebBrowser control的应用:
     
    axWebBrowser.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.axWebBrowser_DocumentComplete);
    object o = null;
    axWebBrowser.Navigate2(ref __url, ref o, ref o, ref o, ref o);
    // ...........

    private void axWebBrowser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
    {
        MessageBox.Show("Document Completed");
        IHTMLDocument2 doc = (IHTMLDocument2)axWebBrowser.Document;
        // ........
    }

    在开发机器上运行正常,在其它(测试)机器上,axWebBrowser_DocumentComplete()不执行!

    google一下,发现很多人在hosting WebBrowser control时遇到问题,问题各种各样,说明在.NET中与IE这样复杂的COM component进行interop,实在不是一件easy的活儿!

    在与这个问题fighting了两天之后,game终于over了!

    IHTMLDocument2的wrapper在Microsoft.mshtml.dll中,而测试机器虽然安装了.NET Framework,但Global Assembly Cache中仍然没有这个程序集,在运行无法加载。下载一份Microsoft.mshtml.dll放入程序所在目录,则一切OK!

    两点疑惑:

    1、虽然由于无法加载Microsoft.mshtml.dll而导致IHTMLDocument2失败,但前面的MessageBox.Show()也不执行!

    2、既然安装了.NET Framework,GAC中为什么没有Microsoft.mshtml.dll呢?如果Microsoft.mshtml.dll是在SDK(VS 2005)中,那为什么VS不生成redistributed assembly呢?

    有消息说,Microsoft有一支200人的团队在从事IE 8的开发,IE这个玩意儿,和Windows一样,越搞越复杂,越搞越慢。