ASP. net mvc monitoring diagnostics, localization and caching, asp. netmvc

Source: Internet
Author: User

ASP. net mvc monitoring diagnostics, localization and caching, asp. netmvc

This blog explains some common things of the asp.net mvc project, including monitoring and diagnosis, localization, and caching. Although the first two seem to be unrelated to asp.net mvc. However, if you really need to implement the asp.net mvc project, it will be associated. This blog will introduce these three concepts separately to guide some design during development.

V1. Monitoring and Diagnosis 1. Overview:

Monitoring and Diagnosis allows you to monitor apps and obtain data through software or monitoring service providers to analyze APP errors and data.

1. 2. Back scene:

With the rapid growth of the Internet, personal websites, corporate websites, community websites ...... More and more websites are competing, and thus derived from the monitoring of websites. website monitoring is the webmaster, enterprise, community ...... You can use software or website monitoring service providers to monitor your website and obtain data to analyze website errors and data. After a website is deployed, it usually encounters various possibilities of errors or downtime. Therefore, monitoring and diagnosis are very important.

1. 3. Common monitoring:

There are many methods or tools for monitoring the asp.net mvc web site, there is an official healthMonitoring green monitoring tool, some third-party monitoring tools, some monitoring tools using their own log writing method, and sending alarm emails to webmasters. There are also some performance, performance, memory, CPU and disk read/write monitoring, and some open-source monitoring tools such as Munin.

In short, there are many monitoring methods. Of course, most of the projects are deployed on the cloud, so you may not need to perform monitoring on your own, here we will introduce the most common green monitoring in windows.

. Implementation Monitoring:

Create a new MVC project and write an error on the Index page that is opened by default, force throw, and then run. The corresponding code and effects are as follows:

Obviously, an error is returned here. Now let's open the Windows event viewer (win + q search "event viewer" for the Chinese system ").

V2. Localization. Concepts:

Localization refers to the organization of production, sales, and other processes of products according to the needs of specific countries/regions or language markets in order to improve market competitiveness and reduce costs during the internationalization of enterprises, it conforms to the organizational change process of specific regional markets.

2. Back scene:

In the era of economic globalization, large enterprises initially produced products in their own countries and sold their products in their own countries. With the increasing production scale and product reputation, their products began to flow in the international market. In order to further expand the share of the international market, some of the raw material procurement and processing processes are moved to the form of organization that is completed by the local industrial workers in the place of product demand, which is called Enterprise localization. The advanced form of enterprise localization is to integrate local society and work with local enterprises to promote the progress and development of the destination society.

2. 3. Common Localization:

Let's take a very simple example, which is also the simplest application in localization. Let's take a look at the specific steps of simple localized applications.

2.3.1. Page code:

@{    ViewBag.Title = "Home Page";    var prices = 10.0m;    var date = DateTime.Now;}<div>@prices.ToString("c")</div><div>@date.ToShortDateString()</div>

The code above is very common, that is, to output the currency information and display the short date format on the page. What we need to do is to display the language, currency, or time in different countries and regions in different ways. We need to make this code display the corresponding format according to different regions.

2.3.2. Set Web. config:

Culture: Specify the default culture for processing incoming Web requests.

UiCulture: Specifies the default culture for searching for resources dependent on the region. To view valid Regional strings.

Both attributes are set to auto.

2.3.3. Browsing effect:

  • English Effect

    2. 4. Resource file:

    Resource file localization is also a very common method, and Microsoft has also integrated Resource. resx for developers, which is very convenient to use.

    2.4.1. Create a resource file:

    We will first create two Resource files: a default Resource file Resource. resx and a Chinese Resource file Resource. zh. resx. Pay attention to setting the access modifier to public. The structure of the two resource files is as follows:

    2.4.2. Page code:

    <div>@Resource.Hello @Resource.Name</div><div>@prices.ToString("c")</div><div>@date.ToShortDateString()</div>

    2.4.3. Browsing effect:

    • English Effect

      The default language of the current browser is English, so the result is: Hello CNBlogs

    • Chinese Effect

      In the language settings of the Internet option of the early browser, we can set the current language to Chinese, so the result is: Hello blog

    V3. Cache. Concepts:

    Cache is the buffer for data exchange (called Cache). When a hardware wants to read data, it first looks for the required data from the Cache. if it finds the data, it is executed directly, if it cannot be found, it will be found from the memory. Since the cache runs much faster than the memory, the cache function is to help the hardware run faster.

    3.2. features:

    Cache refers to a memory that can exchange high-speed data. It exchanges data with the CPU before the memory, so the speed is very fast. L1 Cache (primary Cache) is the first high-speed Cache of the CPU. The built-in L1 high-speed cache capacity and structure have a great impact on CPU performance. However, high-speed buffer memory is composed of static RAM and has a complex structure, when the area of the CPU core cannot be too large, the capacity of the L1-level high-speed cache cannot be too large. Generally, the L1 cache capacity is 32-256KB. L2 Cache (second-level Cache) is the second-level high-speed Cache of the CPU, which is divided into two chips: internal and external. The internal chip second-level cache runs at the same speed as the clock speed, while the external second-level cache is only half of the clock speed. The L2 high-speed cache capacity also affects CPU performance. The principle is that the larger the cache, the better. The L2 cache of a general desktop CPU is generally kb to 2 MB or higher, the CPU L2 cache for laptops, servers, and workstations can be up to 1 MB-3 MB.

    3.3.OutputCacheAttribute:

    3.3.1. Introduction:

    Using the output cache, you can store the output of operation methods in the memory of the Web server. For example, if the operation method shows a view, the view page is cached. The cached page is then available for subsequent requests. The output cache can save the time and resources required to re-create the operation method of the application. In ASP. net mvc, you can use the OutputCacheAttribute feature to mark the operation methods to cache the output. If you use the OutputCacheAttribute feature to mark a controller, the output of all operation methods in the Controller will be cached.

    3.3.2. instance:

    3.3.2.1. Code Demonstration:

    public class HomeController : Controller    {        [OutputCache (Duration=60)]        public ActionResult Index()        {            return View();        }    }

    3.3.2.2. Code explanation:

    Here, we add an Attribute like [OutputCache (Duration = 60)] to the action of/Home/Index, place a breakpoint in the Action of/Home/Index, and press F5 to execute, you will find that only the first execution will go into the breakpoint, And in this 60 seconds, how do you refresh the execution will not go into the breakpoint. This is a simple 60-second cache.

    The above code mainly uses the parameter Duration to implement caching. If we want to configure the cache time, we can also use the CacheProfile parameter. The specific implementation code is as follows:

    C # code

    public class HomeController : Controller    {        [OutputCache (CacheProfile="long")]        public ActionResult Index()        {            return View();        }    }

    Modify web. config

    3.3.3. More information:

    There are many interesting parameters about OutputCacheAttribute, which can help us implement various caching methods you want.

    OutputCacheAttribute can be set with many parameters, which vary according to different requirements and business needs. For more information about OutputCacheAttribute parameters, see here.

    V blog Summary

    The introduction to monitoring diagnostics, localization, and caching is here. If you are interested in or want to extend these three directions, you can discuss them together.

    The above information is from the MSDN/Baidu encyclopedia. I would like to thank the MSDN/encyclopedia for its help in this blog and for helping the bloggers learn, work, and live.

     


    Author:Please call my first brother
    Exit: http://www.cnblogs.com/toutou/
    About the author: focused on Microsoft platform project development. If you have any questions or suggestions, please kindly advise me!
    Copyright Disclaimer: The copyright of this article is shared by the author and the blog site. You are welcome to reprint this article. However, you must keep this statement without the author's consent and provide the original article link clearly on the article page.
    We hereby declare that all comments and private messages will be replied immediately. You are also welcome to correct the mistakes and make progress together. Or directly send a private message to me.
    Support blogger: If you think the article is helpful to you, click the bottom right corner of the article[Recommended]. Your encouragement is the greatest motivation for the author to stick to originality and continuous writing!

Related Article

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.