19th. Troubleshoot and troubleshoot run-time issues with web programs

Source: Internet
Author: User

1. Overview

Several common run-time issues include error data, slower-than-expected responses, unknown behavior, or unhandled exceptions.

Visual Studio provides tools such as troubleshooting, tracing, and logging to help troubleshoot your system. In some cases, the diagnostic code needs to be inserted.

This chapter includes troubleshooting performance, security issues, and run-time errors, implementing traces, logging (including using attributes), and debugging (including IntelliTrace), using code contracts to enforce conditional validation, enabling and configuring health monitoring.

2. Main content

2.1 Troubleshooting performance issues, security issues, and run-time errors

Performance issues are frustrating for users

Security issues can cause all problems, both internal and external, if the user's data is compromised by a security threat.

Run-time errors affect all, including performance, security, and incorrect data generation.

2.1.1 Using the Performance Wizard (Performance Wizard)

The Performance wizard provided by VS2012 is a performance analysis tool.

Contains CPU sampling, instrumentation,. NET memory allocation (sampling), and Resource contention data (concurrency).

      

CPU sampling: Is a lightweight monitoring, more for initial checks, providing further system check direction.

Instrumentation: The count and time of the method call. is a more intrusive process, and the performance Tools add monitoring code to the component.

. NET memory allocation (sampling): Monitors the allocation of memories. Analyze each object from being created to the process being recycled.

Resource contention data (Con-currency): for multithreaded programs. Provides thread interaction information and information about the threads interacting with the system.

2.1.2 Using Visual Studio Profiler

Visual Studio provides a Profiler that provides completion tracking information for calls to operations in the system.

The Visual Studio Profiler primarily monitors activities and logs them relative to performance monitoring tools. This detailed data can be used to do more in-depth analysis.

      

This icon shows the CPU usage per second.

2.1.3 Using Performance Monitor (Performance Monitor)

Performance monitors are tools that are provided by Windows Server and can be used in production environment monitoring programs.

      

2.2 Troubleshooting security Issues

In general, security issues are related to authentication and authorization access.

Authentication issues, you need to consider the scope of the validation issue, whether it is all users, a specific user, or a group of users.

Authorization to access the problem is also a similar idea. Determine the possible cause of the problem depending on the scope.

2.3 Implementing tracing, logging, and debugging

Tracing is a technique that can be analyzed while the program is running.. NET built-in support for tracking.

Trace.writeif (Somevalueistrue, "Message").

A log is the process of recording information. NLog and log4net are two common open source logging tools.

You can use Try-catch to manually handle debugging, error, and trace information, or you can automate it by using Handleerrorattribute.

Handleerrorattribute can be used for actions, controllers, or globally.

[HandleError (Exceptiontype=typeof(system.ioexception), view="fileerror")]

    

protected Override voidonexception (Exceptioncontext exceptioncontext) {if(exceptioncontext.ischildaction) {//we don ' t want to display the error screen if it's a child action,        Base.         Onexception (Exceptioncontext); return; }              //log the exception in your configured loggerLogger.Log (exceptioncontext.exception); //Handle when the app isn't configured to use the custom error path    if(!exceptionContext.HttpContext.IsCustomErrorEnabled) {exceptioncontext.exceptionhandled=true;  This. View ("ErrorManager"). Executeresult ( This.     ControllerContext); } }

2.4 Using code contracts to enforce conditional validation

Code contracts are introduced in. net4.0, allowing developers to add restrictions to the program. There are three types of:

A. Verify the input criteria before the preconditions method executes.

B. The invariants method prevents illegal state from occurring during execution.

C. When the Postconditions method is complete, check the results to be output.

Using a code contract requires a different way to manage the exception handling process.

Internal Article GetArticle (int  ID) {     0);      // }

The invariant check is used to ensure that no illegal state is present in the class.

protected void manageinvariant () {     System.Diagnostics.Contract.Invariant (this0);}

Postconditions

Internal Article GetArticle (int  ID) {     0);      System.Diagnostics.Contracts.Contract.Ensures (             contract.resultsnull);      // }

There are other ways to handle breach of contract, and you can add custom processing logic by registering the contract.contractfailed event.

2.5 Enabling and configuring health monitoring

Not to be continued ...

19th. Troubleshoot and troubleshoot run-time issues with web programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.