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 ...
随机推荐
- 【python】面向对象
面向对象编程--Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 类class 实例(i ...
- JavaScript Module Pattern: In-Depth
2010-03-12 JavaScript Module Pattern: In-Depth The module pattern is a common JavaScript coding patt ...
- 网页for循环get测试
for(var i=0;i<10000;i++) { var request = new XMLHttpRequest(); request.open("GET"," ...
- 通过工厂方式配置bean
src\dayday\CarFactoryBean.java package dayday;import org.springframework.beans.factory.FactoryBean;/ ...
- 招聘信息:无线产品研发总监 60-100W
招聘信息:某知名电商公司诚招: 无线产品研发总监 60-100W 招聘人数:1名 岗位描述: 熟悉互联网产品业务流程,完成产品功能的概念设计个原型展示: 进行市场调查和分析,相关用户研究和信息整理,提 ...
- mac OS X Yosemite (10.10.5) 下 安装vim 7.4笔记
摘要 前言 需求与mac OS X 自带vim版本的冲突 默认Python解释器问题 并非Mac自带python的 homebrew 1. 前言 本文为自己作死折腾的问题记录 2. 需求与mac OS ...
- 关于Python中的文件操作(转)
总是记不住API.昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Pyth ...
- Android 标题栏菜单设置与应用(popupWindow的应用)
效果图
- IE7下如何判断复选框是否被选中(利用jquery)
var checkM; $(".rate-mainL .checkM").click(function(){ var checkM=$("input[name='chec ...
- C#在Dictionary中使用枚举作为键
Enum类型没有实现IEquatable接口,Dictionary中使用Enum作为键时,将发生装箱,使效率降低. 此时可用Dictionary中一个接收IEqualityComparer<T& ...