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. pb自动注册ole控件

    方法一:  1.手工注册OCX控件 将该控件随程序一起发布,然后,将此文件拷到windows\system,或者直接放在本运行目录,然后执行dos命令,run( "regsvr32   *. ...

  2. css3--布局正六边形

    怎样布局正六边形?-->如果不能直接布局,就只能采用图形的组合.-->既然是正六边形,则: -->AB=2分之根号3乘2倍的边长,也就是对于矩形ABCD来说,AB是BD的根号3倍(也 ...

  3. jQuery中的$.grep()方法的使用

    标签: it 分类: jQuery grep()方法用于数组元素过滤筛选 grep(array,callback,invert) array:待过滤数组; callback:处理数组中的每个元素,并过 ...

  4. 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

  5. Spring3.0 与 MyBatis框架 整合小实例

    本文将在Eclipse开发环境下,采用Spring MVC + Spring + MyBatis + Maven + Log4J 框架搭建一个Java web 项目. 1. 环境准备: 1.1 创建数 ...

  6. Hadoop原理介绍

    Hadoop核心之HDFS 架构设计   老嗨 2015-09-18 16:55:00 浏览225 评论0 摘要: 概述:HDFS即Hadoop Distributed File System分布式文 ...

  7. PKU 1006

    数学问题吧,有兴趣的可以研究一下“中国剩余定理” // 1006.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include < ...

  8. Bzoj索引

    1001 : http://ideone.com/4omPYJ1002 : http://ideone.com/BZr9KF1003 : http://ideone.com/48NJNh1004 : ...

  9. HDU 5113 dfs剪枝

    题意:告诉格子规格,颜色个数,以及每个颜色能涂得格子数目,问是否能够实现相邻两个格子的颜色数目不相同. 分析:因为数据很小,格子最多是5 * 5大小的,因此可以dfs.TLE了一次之后开始剪枝,31m ...

  10. 610K图纸打印新版增值税发票不完整的调整方法

    新版增票页面设置增票向下0.8向右-10,10刻度进纸测试 向右调整可能会有些出入 根据情况微调即可.