Chapter 4: Troubleshoot and debug web applications
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的更多相关文章
- [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 ...
- Create Advanced Web Applications With Object-Oriented Techniques
Create Advanced Web Applications With Object-Oriented Techniques Ray Djajadinata Recently I intervie ...
- 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 ...
- Progressive Web Applications
Progressive Web Applications take advantage of new technologies to bring the best of mobile sites an ...
- Developing RIA Web Applications with Oracle ADF
Developing RIA Web Applications with Oracle ADF Purpose This tutorial shows you how to build a ric ...
- Setting up Scatter for Web Applications
[Setting up Scatter for Web Applications] If you are still using scatter-js please move over to scat ...
- SpringBoot(五) Web Applications: MVC
统一异常处理 SpringBoot的默认映射 /error 码云: commit: 统一异常处理+返回JSON格式+favicon.ico 文档: 28.1.11 Error Handling 参考 ...
- 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 ...
- 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 ...
随机推荐
- Web前端开发的前景与用处
随着时代的发展,现在从事IT方向的人有很多,所以励志要成为前端开发工程师的人有很多.当然也有很多人在犹豫不知道该从事哪个方向,我今天就是来给大家分析一下Web前端开发的前景.包括工作内容,发展前景和薪 ...
- 移动混合开发之HTML5在移动开发中的准则
1.尽量单页面开发 2.慎重选择前端UI框架,新手最好自己动手. 3.动画特效达到60fps 4.长度单位是用rem,即字体的宽度,字体宽度可根据 window.width/number.
- android使用镜像 Android sdk 和源码等
HTTP Proxy Server:mirrors.neusoft.edu.cn HTTP Proxy Port :80
- 排序系列 之 折半插入排序算法 —— Java实现
基本思想: 折半插入算法是对直接插入排序算法的改进,排序原理同直接插入算法: 把n个待排序的元素看成一个有序表和一个无序表,开始时有序表中只有一个元素,无序表中有n-1个元素:排序过程即每次从无序表中 ...
- android最常用的退出方法
public class AppUtils extends Application{ private List<Activity> activityList = new LinkedLis ...
- 在win7环境下安装python2.6.6
Python2.x与3.x语法并不相同,这里装的是2.6.6的版本. 1.下载Python2.6.6: https://www.python.org/downloads/ 根据自身计算机的特点选择Py ...
- linux 录制并回放终端会话
发现一个比较好玩的命令,然后这块做一下记录 以下内容复制来源于 LINUX shell 脚本攻略第二版 当你需要为别人在终端上演示某些操作或是需要准备一个命令行教程时,通常得一边手动输入命令一边演示, ...
- BZOJ 2002 && BZOJ 2409 LCT && BZOJ 3282 初步练习
#include <cstdio> ; inline void Get_Int(int & x) { ; ') ch=getchar(); +ch-'; ch=getchar(); ...
- Node黑客开发的10个好习惯(2016)
在2015年底之际,javascript开发者已经掌握了大量的工具.最后一次我们调查的时候,现代化的JS蓝图才刚刚出现.今天,我们很容易在JS的庞大生态系统中迷失,而成功的团队大部分时间都遵守着JS开 ...
- easyui 筛选数据及仅允许选择数据
先说需求,本地已缓存数据源,用户输入拼音码或编号,筛选数据作为新的数据源,然后通过键盘选择. 再说问题,easyui combogrid控件,在mode为local,也就是将数据源缓存在本地的情况下, ...