My Nopcommerce Tour (6): App launch

Source: Internet
Author: User
Tags nopcommerce website performance

First, the basic introduction

An Global.asax file (also known as an ASP. NET application file) is an optional file that contains code that responds to application-level and session-level events raised by the ASP. NET or HTTP module.

Application_Start is one of the events that is triggered when the first instance of the HttpApplication class is created, which allows you to create an object that can be accessed by all HttpApplication instances.

Simply put, Application_Start () is a method that is executed when an ASP. NET application starts and can be understood as an application portal.

Second, Code Analysis Application_Start ()

1. For safety reasons, remove the x-aspnetmvc-version head

2. Initializing the context

3. Determine if the database is initialized

3.1 Loading the configuration file ~/app_data/settings.txt

3.2 Read the content, if there is a connection string indicates that the database has been initialized

4. Clear the View engine

5. Add some functional meta-data

6. Register common MVC objects, including Area,route

7. Turn off MVC default labeling feature model validation, add fluentvalidation (a validation component)

8. Start a scheduled task

8.1 Initialize all created scheduled tasks

8.2 Starting a timed task thread

9. Depending on the configuration, whether to start Miniprofiler (ASP. NET MVC Performance analysis tool to monitor website performance)

9.1 The installation is false by default and is configured in [dbo]. [Setting] table, name is Storeinformationsettings.displayminiprofilerinpublicstore

9.2 Configuration Methods

9.2.1 go to the admin page and go to the configuration menu

      

9.2.2 retrieves the Storeinformationsettings.displayminiprofilerinpublicstore, locates the entry, modifies the value

      

9.2.3 start effect, in the upper left corner of the page can see the page execution time, reference Miniprofiler related information

      

10. Record App startup logs

10.1 Instantiation via Dependency Injection

10.2 Logs are written to the database, table [dbo]. [Log]

11. The code is as follows

1         protected voidApplication_Start ()2         {3             //disable "x-aspnetmvc-version" header name4Mvchandler.disablemvcresponseheader =true;5 6             //Initialize engine context7Enginecontext.initialize (false);8 9             BOOLdatabaseinstalled =datasettingshelper.databaseisinstalled ();Ten             if(databaseinstalled) One             { A                 //Remove all View engines - ViewEngines.Engines.Clear (); -                 //except the Themeable Razor view engine we use theVIEWENGINES.ENGINES.ADD (Newthemeablerazorviewengine ()); -             } -  -             //Add Some functionality on top of the default Modelmetadataprovider +Modelmetadataproviders.current =NewNopmetadataprovider (); -  +             //registering some regular MVC stuff A Arearegistration.registerallareas (); at registerroutes (routetable.routes); -              -             //Fluent Validation -Dataannotationsmodelvalidatorprovider.addimplicitrequiredattributeforvaluetypes =false; -MODELVALIDATORPROVIDERS.PROVIDERS.ADD (NewFluentvalidationmodelvalidatorprovider (Newnopvalidatorfactory ())); -  in             //Start Scheduled Tasks -             if(databaseinstalled) to             { + TaskManager.Instance.Initialize (); - TaskManager.Instance.Start (); the             } *  $             //MiniprofilerPanax Notoginseng             if(databaseinstalled) -             { the                 if(enginecontext.current.resolve<storeinformationsettings>(). Displayminiprofilerinpublicstore) +                 { AGLOBALFILTERS.FILTERS.ADD (NewProfilingactionfilter ()); the                 } +             } -  $             //Log Application Start $             if(databaseinstalled) -             { -                 Try the                 { -                     //LogWuyi                     varLogger = enginecontext.current.resolve<ilogger>(); theLogger.information ("Application started",NULL,NULL); -                 } Wu                 Catch(Exception) -                 { About                     //don ' t throw new exception if occurs $                 } -             } -}

My Nopcommerce Tour (6): App launch

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.