2

学习MS Visual Web Developer和ASP.NET 4.0。我似乎更喜欢查看页面源代码并将鼠标悬停在绿色波浪风格下划线的区域上,而不是使用MS Visual Web Developer中的调试选项。当我把鼠标悬停在他们身上时,它告诉我什么是错误的,然后我才明白从那里做什么。在Microsoft Visual Web Developer 2010 Express中进行调试

对于一个具体的例子,我有:

<td background="images/separater.png" width="5"> 

盘旋在它之后,我用这个替代它:

<td style="background-image: url(images/separater.png)" width="5"> 

使开关,绿色波浪线消失后,所以我假设实际上我调试了那个特定的代码片段。我相信我只是让它与ASP.NET 4.0 Framework兼容。

我独自留下的唯一绿色波浪线就是Facebook插件等社交插件。无论如何,我的问题是:是我在做什么(一)正确,(二)重要,和(三)一样好使用MS Visual Web Developer中的调试选项?因为你没有使用Debug命令

回答

1

大多数ASP.NET开发人员考虑这个调试,F5调试服务器端代码(通常是C#或VB.NET代码)。有关该过程的更多详细信息,请参阅Walkthrough: Debugging Web Pages in Visual Web Developer

你所说的绿色波浪线实际上是关于你的HTML的警告。在这种情况下,表格的背景属性不是official HTML specification的一部分,这是Visual Web Developer Express警告你的。因此,您没有使您的代码与ASP.NET 4.0 Framework兼容,但您确实使您的标记符合HTML标准。

如果你的代码是不是与ASP.NET 4.0兼容,你通常会死亡的黄色画面,在这一点上,你可能需要调试找到错误或异常

Example yellow screen of death

的原因

要回答你的问题:你在做什么是(a)正确的,(b)对于浏览器兼容性是重要的,(c)不涉及Visual Web Developer Express中的调试功能。

+0

非常感谢Michiel花时间回复。我完全理解你在说什么。我已经处理了我网站上的所有警告,除了一对夫妇(它不喜欢我为我的社交书签之一提供的Facebook插件,但无论如何我都离开了它)。所有的oyur信息都很有用,并且感谢您发布MS调试网站的链接。保重! – 2011-12-21 23:41:11

1

我真的更喜欢Visual Studio 2010中的“附加到进程”选项,但是如果您正在使用Visual Web Developer(例如在调试服务器上)来调试已部署的网站或Web应用程序,我喜欢使用ASP.NET开发服务器(通过点击播放启动)的此方法。如果未明确处理,则应用程序中引发的每个异常(除了来自asmx Web服务)都将在此方法中捕获。只要确保在您的网站根文件夹中创建一个“例外”文件夹。调试器在点击Visual Web Developer 2010中的播放按钮后启动应用程序需要很长时间,所以我更愿意在IIS中设置站点,然后将堆栈跟踪发送到文件,因为这是您关心的问题无论如何。如果您需要有关异常变量的更多详细信息,请在发生异常的位置捕获异常,并在其中引入一个具有该变量值的新异常。当搜索最新的异常调用堆栈时,只需打开该文件夹并对文件进行排序即可。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.SessionState; 

namespace WebApplication1 
{ 
    public class Global : System.Web.HttpApplication 
    { 

     protected void Application_Start(object sender, EventArgs e) 
     { 

     } 

     protected void Session_Start(object sender, EventArgs e) 
     { 

     } 

     protected void Application_BeginRequest(object sender, EventArgs e) 
     { 

     } 

     protected void Application_AuthenticateRequest(object sender, EventArgs e) 
     { 

     } 

     protected void Application_Error(object sender, EventArgs e) 
     { 
      Exception ex = Server.GetLastError(); 
      try 
      {     
       WebApplication1.Global.WriteDataToFile(null, ex.StackTrace); 
      } 
      catch 
      { 
       throw ex; 
      } 
     } 

     public static void WriteDataToFile(string filePath, string contentToWrite) 
     { 
      if (filePath == null) 
      { 
       filePath = string.Format(@"C:\web_root\exceptions\debug.{0:yyyy-MM-dd_hh.mm.ss.tt}.txt", DateTime.Now); 
      } 

      System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath); 
      sw.WriteLine(contentToWrite); 
      sw.Close(); 
     } 

     protected void Session_End(object sender, EventArgs e) 
     { 

     } 

     protected void Application_End(object sender, EventArgs e) 
     { 

     } 
    } 
} 
相关问题