visual studio撰写的日志

试图运行项目时出错:无法在web服务器上启动项目的解决办法

在Visual Studio中启动Web项目的调试时,出现如下的错误(错误提示见附件): 
    自动附加到计算机“Firehack”上的进程“[5676] w3wp.exe”失败。错误代码为 0×8013134b
    Auto-attach to process ‘[2440] w3wp.exe’ on machine ‘Firehack’ failed. Error code 0×8013134b. 

其中关键的一点是出现了一个错误代码 0×8013134b。

出现这个错误的原因很简单:因为安装ASP.NET 2.0(或者针对.NET 2.0的补丁) 后,.NET 2.0 自动将IIS中所有的站点属性中的“ASP.NET版本” 设置为 2.0.50727,虽然站点仍旧能够正常访问,但是Visual Studio 2003就无法启动调试了的。

因此解决方法也就出现:

  1. 打开“Internet 信息服务(IIS)管理器),开始-运行-inetmgr;
  2. 在出现问题的站点上右键-属性;
  3. 选中“ASP.Net”标签;
  4. 修改“ASP.NET版本” 为 1.*.*;
  5. 应用后,重新启动调试。

————–英文信息—————

Attached the process w3wp.exe on my machine.  Then I got the following error:

Auto-attach to process ‘[2440] w3wp.exe’ on machine ‘…’ failed. Error code 0×8013134b.

The problem was that I had installed .NET 2.0 which had registered ASP.NET 2.0 on the Web Site I was trying to debug.

Fixing it is simple:

  • Run the IIS Manager
  • Right click on the web site with the problem
  • Click the ASP.NET tab
  • Change the ASP.NET version from 2.something to 1.something in the combo and debugging works again

Upon changing to 1.something, the debugging worked.

图片附件:
0x8013134b.png

程序“[1912] w3wp.exe: DefaultDomain”已退出,返回值为 0 (0×0)

使用Visual Studio 2003/2005调试ASP.NET程序时出现如下错误,从而无法调试:
程序“[1912] w3wp.exe: DefaultDomain”已退出,返回值为 0 (0×0)。
  对应的英文信息为: 
The program ‘[5772] w3wp.exe: demo’ has exited with code 0 (0×0).
这个问题是IE8的 Loosely-Coupled Internet Explorer (LCIE) 引起的,解决方法如下:

对于Windows 2003/Windows XP 操作系统:
1)  Open RegEdit //打开注册表编辑器
2)  Browse to HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main //定位到【HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main】
3)  Add a dword under this key called TabProcGrowth //新建名称为 TabProcGrowth 的Reg_DWORD(整数值)
4)  Set TabProcGrowth to 0 //设置 TabProcGrowth 的值为 0
重新启动调试,就恢复正常

如果是Vista或者更新的Win7上则需要:turn off protected mode。

解决方案来源:
VS 2005 Debugger crashing with IE 8 Beta 2

IE 8 has a feature called Loosely-Coupled Internet Explorer (LCIE) which results in IE running across multiple processes. 
http://www.microsoft.com/windows/internet-explorer/beta/readiness/developers-existing.aspx#lcie

Older versions of the Visual Studio Debugger get confused by this and cannot figure out how to attach to the correct process.  You can work around this by disabling the process growth feature of LCIE.  Here’s how:

1)  Open RegEdit
2)  Browse to HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3)  Add a dword under this key called TabProcGrowth
4)  Set TabProcGrowth to 0

Since you are running on Windows Server 2003, this is all you should need to do.  If you run into the same problem on Vista or newer, you will also need to turn off protected mode.

附件:error.txt(7215 Byte)

无法在Web服务器上启动调试。与Web服务器通信时出现身份验证错误

使用Visual Studio 2005(Visual Studio 2008亦存在此问题)调试设置了主机头的网站时出现如下错误信息:

—————————
Microsoft Visual Studio
—————————
无法在 Web 服务器上启动调试。与 Web 服务器通信时出现身份验证错误。请参阅“帮助”以协助解决问题。
—————————

项目属性的Web中设置“项目URL”为 http://www.msdi.cn/MultiWeb

如果将“项目URL”指定为 localhost 则在设置时不会出现以上的错误,所以排除了网上绝大部分文章提供的“集成Windows身份验证”,项目属性中“启用调试”的解决方案。

真正的解决方法如下:

步骤 1: 禁用环回检查
请遵循以下步骤:
1. 打开注册表编辑器(单击 开始 , 单击 运行 , 类型 regedit然后单击 确定 )。
2. 中注册表编辑器, 找到并单击以下注册表项:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
3. 右击 Lsa , 指向 新建 , 然后单击 DWORD 值 。
4. 类型 DisableLoopbackCheck然后按 Enter。
5. 右击 DisableLoopbackCheck , 然后单击 修改 。
6. 在 数值数据 框中, 键入 1然后单击 确定 。
7. 退出注册表编辑器, 并重新启动计算机。 (可以不重启计算机)

步骤 2: 指定主机名
要指定主机名, 映射到环回地址并可连接到 Web 站点上, 请按照下列步骤:
1. 打开注册表编辑器(单击 开始 , 单击 运行 , 类型 regedit然后单击 确定 )。  。
2. 中注册表编辑器, 找到并单击以下注册表项:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
3. 右击 MSV1_0 , 指向 新建 , 然后再单击 多字符串值 。
4. 类型 BackConnectionHostNames然后按 Enter。
5. 右击 BackConnectionHostNames , 然后单击 修改 。
6. 在 数值数据 框中, 键入主机名或主机名为站点所在的本地计算机名称,  确定 。
7. 退出注册表编辑器, 并重新启动 IISAdmin 服务。

这个错误的信息只会出现在特定环境的计算机中:This issue only appears on Web Sites configured with a host header on machines with IIS 6 or IIS 5.1 and the RTM version of the .Net Framework 3.5 SP1.

参考文章:
当您浏览位置 IIS 5.1 或 IIS 6 上的网站并且使用集成身份验证时,会收到 401.1 错误
Debugging A Web Site With A Host Header

关于条件编译:#if #else #endif

条件编译就是按条件对程序的一部分进行编译,其它部分不编译。条件编译的目的是使源代码能更迅速、更容易地进行修改,并使目标代码缩短。

Visual Studio 2003和Visual Studio 2005都提供了条件编译的功能,并且将起作用的代码以高亮显示,被条件排除的错码显示为灰色。

设置条件编译的位置:

Visual Studio 2003:工程属性->配置属性->生成->条件编译常数(Project->Properties->Configuration->Build)
Visual Studio 2005:在打开类库的属性->生成->常规中的"条件编译符号"

条件编译符号需要多个时,使用“,”,“;”,“ ” (逗号,分号,空格)三种符号分隔,都可以 

在以下代码中如果定义了 NET1就执行:
assembly: AssemblyProduct("Discuz!NT 2.0 (.net Framework 1.1)")
如果没有定义就执行:
assembly: AssemblyProduct("Discuz!NT 2.0 (.net Framework 2.x/3.x)")

ASP.net条件编译代码
  1. #if NET1   
  2. [assembly: AssemblyProduct("Discuz!NT 2.0 (.net Framework 1.1)")]  
  3. #else   
  4. [assembly: AssemblyProduct("Discuz!NT 2.0 (.net Framework 2.x/3.x)")]  
  5. #endif  

图片附件:
条件编译.png

图片附件:
设置条件编译后的代码效果.png

自动生成Visual Studio 2005配色方案

选择Visual Studio 2005编辑器的前景色、背景色和对比度自动生成配色方案(*.vssettings),最后通过Visual Studio 2005的“导入和导出设置向导”导入字体和颜色的设置。

访问Visual Studio Theme Generator

以下是Visual Studio Theme Generator 提供的英文帮助

To Create A Theme

  1. Select your Colors and Contrast settings on the left
  2. Press refresh in the preview window
  3. Click Create to save your new theme (ie users will need to file save as on the next screen)

To install the new settings file:

  1. Click tools
  2. Import and Export Settings
  3. Choose ‘Import Selected Environment Settings’ and click Next
  4. Backup current settings and continue
  5. Browse to the download location and click Next
  6. The Next screen you can confirm that you’re overwriting just the fonts and color and click Finish

图片附件:
visual-studio-theme-generator.png

VS2005:由于页中存在错误,无法切换到设计视图

在使用VS2005时经常会出现无法从源视图切换到设计视图的问题。
—————————
Microsoft Visual Studio
—————————
由于页中存在错误,无法切换到设计视图。请更正错误列表中标记为“无法切换:”的所有错误,然后重试。
—————————
确定  
—————————

原因是页面有未闭合的html标记,根据Visual Studio 2005的错误提示找到改过来。

类似的错误提示如下:

错误 29 无法切换视图: 此结束标记没有匹配的开始标记。 F:\SCFD\WebRoot\SCFD\PortalInfor\FocusNewsEdit.aspx 158 8 scfd

错误 41 无法切换视图: 验证 (HTML 4.01): 在标记中属性“class”只能指定一次。 F:\SCFD\WebRoot\SCFD\PrjOutgoingFile\PrjOutgoingFileWflow.aspx 196 38 scfd

即在错误列表中查看提示“”的错误,并更正即可。

图片附件:
visualstudio2005.png