Prevent and troubleshoot runtime issues

  • Troubleshooting performance, security and errors
  • using performance wizard (Vs2012)
  • Using VS profiler (Analyzer | Profiler)
  • Using Performance Monitor
  • NLog/log4net for logging
  • Tracing, Trace.WriteLine("Message")/Write/WriteIf/WriteLineIf
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListerner" initializeData="TracingInfo.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
  • Error logging

    • HandleErrorAttribute
    • overriding controller's OnException: protected override void OnException(ExceptionContext pContext)
  • Enforcing conditions by using code contracts
internal Article GetArticle(int pId)
{
System.Diagnostics.Contracts.Contract.Requires(id > 0);
System.Diagnostics.Contracts.Contract.Ensures( Contract.Results<Article>() != null );
/// some work here
} [ContractInvariantMethod]
protected void ManageInvariant()
{
System.Diagnostics.Contract.Invariant(this.Id < 0 );
}
* Preconditions
* Invariants
* Postconditions

install Code Contracts Editor Extensions from VS Gallery

  • Enabling and configuring health monitoring

    • bufferModes
    • providers
    • profiles
    • rules
    • eventMappings

Design an exception handling strategy

  • Handling exceptions across multiple layers
  • use Application_Error in Global.asax to handle error pages
  • set error information in Web.config as below:
  <customErrors mode="RemoteOnly" default_redirect="ErrorManager/ServerError">
<error statusCode="400" redirect="ErrorManager/Status400" />
<error statusCode="403" redirect="ErrorManager/Status403" />
<error statusCode="404" redirect="ErrorManager/Status404" />
</customErrors>

HTTP 500 erros are generally handled by filters or OnException handlers.

set in <system.webServer> of Web.config

  • Handle first exception
  AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;

  protected void OnFirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{
}

Test web application

  • running unit tests

    • creating mocks by Fakes Assembly (shim/stub)
  using(ShimsContext.Create())
{
System.Fakes.ShimDateTime.NowGet = () => new DateTime(2010,1,1);
TestMethodNow();
}

Debug a Windows Azure application

  • use IntelliTrace
  • use Remote Desktop

Chapter 4: Troubleshoot and debug web applications的更多相关文章

  1. [Windows Azure] Developing Multi-Tenant Web Applications with Windows Azure AD

    Developing Multi-Tenant Web Applications with Windows Azure AD 2 out of 3 rated this helpful - Rate ...

  2. Create Advanced Web Applications With Object-Oriented Techniques

    Create Advanced Web Applications With Object-Oriented Techniques Ray Djajadinata Recently I intervie ...

  3. Model-View-Controller(MVC) is an architectural pattern that frequently used in web applications. Which of the following statement(s) is(are) correct?

    Model-View-Controller(MVC) is an architectural pattern that frequently used in web applications. Whi ...

  4. Progressive Web Applications

    Progressive Web Applications take advantage of new technologies to bring the best of mobile sites an ...

  5. Developing RIA Web Applications with Oracle ADF

      Developing RIA Web Applications with Oracle ADF Purpose This tutorial shows you how to build a ric ...

  6. Setting up Scatter for Web Applications

    [Setting up Scatter for Web Applications] If you are still using scatter-js please move over to scat ...

  7. SpringBoot(五) Web Applications: MVC

    统一异常处理 SpringBoot的默认映射 /error 码云: commit: 统一异常处理+返回JSON格式+favicon.ico 文档: 28.1.11 Error Handling 参考 ...

  8. Combining HTML5 Web Applications with OpenCV

    The Web Dev Zone is brought to you by Stormpath—offering a pre-built Identity API for developers. Ea ...

  9. a simple and universal interface between web servers and web applications or frameworks: the Python Web Server Gateway Interface (WSGI).

    WSGI is the Web Server Gateway Interface. It is a specification that describes how a web server comm ...

随机推荐

  1. LRU Cache实现

    最近在看Leveldb源码,里面用到LRU(Least Recently Used)缓存,所以自己动手来实现一下.LRU Cache通常实现方式为Hash Map + Double Linked Li ...

  2. C#类的继承,方法的重载和覆写

    在网易云课堂上看到唐大仕老师讲解的关于类的继承.方法的重载和覆写的一段代码,注释比较详细,在此记下以加深理解. 小总结: 1.类的继承:允许的实例化方式:Student t=new Student() ...

  3. Nginx + uwsgi

    1. 安装uwsgi依赖yum groupinstall "Development Tools"yum install pythonyum install python-devel ...

  4. 细说JAVA反射

    Reflection 是 Java 程序开发语言的特征之一,它允许运行中的 Java 程序对自身进行检查,或者说“自审”,并能直接操作程序的内部属性.例如,使用它能获得 Java 类中各成员的名称并显 ...

  5. mvc 导入,导出excel

    最近主要做导入excel 在网上查询了代码 public FileResult DownLoadExcelJiZuChaXunGenRenXiaoFeiJiLu() { DataTable dt = ...

  6. Cordova学习(一) 环境搭建

    一.什么是cordova Cordova提供了一组设备相关的API,通过这组API,移动应用能够以JavaScript访问原生的设备功能,如摄像头.麦克风等. Cordova还提供了一组统一的Java ...

  7. js日期重写

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  8. html学习心得

    注释:浏览器会自动地在段落的前后添加空行.(<p> 是块级元素) 提示:使用空的段落标记 <p></p> 去插入一个空行是个坏习惯.用 <br /> 标 ...

  9. super作用

    super()的作用: super可以用来访问超类的构造方法和被子类所隐藏的方法,如果子类中有方法与超类中的方法名称和参数相同,则超类中的方法就被隐藏起来,也就是说在子类中重载了父类中的方法. 引用父 ...

  10. RSS阅读器python实现概述

    这边简单说一下最近倒腾的RSS阅读器的小东东,RSS阅读器估计很多人用过或者自己动手实现过.首先wudagang0123多年前提供的一个示例:http://bbs.chinaunix.net/foru ...