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 ...
随机推荐
- 数据类型int、bigint、smallint 和 tinyint范围
bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字).存储大小为 8 个字节. int ...
- Python的平凡之路(17)
一.认识jQuery jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设 ...
- jsp中的正则表达式
sp中${}----是EL表达式的常规表示方式目的是为了获取{}中指定的对象(参数.对象等)的值如:${user.name}<====>User user = (User)request( ...
- qt做触摸屏演示程序
界面效果图: 参考资料: http://blog.csdn.net/orz415678659/article/details/9136575 这个最重要.. https://www.oschi ...
- 自己动手做logo
本文主要记录用 coreDraw 和ps 做公司logo . 我修改的logo.效果还不错. 1 矢量图 和位图的区别 http://jingyan.baidu.com/article/54b6b9c ...
- jdk 编译器 对final字段的处理
class FinalTest{ void a(){ final int i=10; int j=10; } } stack=2, ...
- Selenium 2 入门
在多个浏览器中进行 Web 应用程序的端到端功能测试 Selenium 是一款有名的 Web 应用程序测试框架,用于进行功能测试.新版本 Selenium 2 结合了 Selenium 1 和 Web ...
- C++调用V8与JS交互
C++访问JS函数 C++部分: /** * COMPILE foo.js AT THE FIRST COMMAND PROMPT TO RUN foo.js */ #include <v8.h ...
- 深入浅出REST
不知你是否意识到,围绕着什么才是实现异构的应用到应用通信的“正确”方式,一场争论正进行的如火如荼:虽然当前主流的方式明显地集中在基于SOAP.WSDL和WS-*规范的Web Services领域,但也 ...
- react native 之上传文件
最近遇到react native中需要上传一些图片到后台.期间,找了一些第三方上传插件,感觉不太好用,要么只支持一个平台,要么会对其他第三方造成影响,实在无奈.只能直接使用fetch上传.其中上传文件 ...