我的NopCommerce之旅(6): 应用启动
一、基础介绍
Global.asax 文件(也称为 ASP.NET 应用程序文件)是一个可选文件,该文件包含响应 ASP.NET 或 HTTP 模块所引发的应用程序级别和会话级别事件的代码。
Application_Start是其中一个事件,在HttpApplication 类的第一个实例被创建时,该事件被触发它允许你创建可以由所有HttpApplication 实例访问的对象。
简单来说,Application_Start()就是一个ASP.NET应用程序启动时执行的方法,可以理解为应用程序入口。
二、代码分析Application_Start()
1.出于安全考虑,去除X-AspNetMvc-Version头
2.初始化上下文
3.判断是否初始化数据库
3.1 加载配置文件~/App_Data/Settings.txt
3.2 读取内容,若存在连接字符串则说明已初始化数据库
4.清空视图引擎,添加自定义视图引擎ThemeableRazorViewEngine,支持前台和后台页面分离,及主题适配。
5.增加一些功能性的元数据
6.注册常见的MVC物件,包括Area,Route
7.关闭MVC默认的标注特性Model验证,添加FluentValidation(一种验证组件)
8.启动定时任务
8.1 初始化所有创建的定时任务
8.2 启动定时任务线程
9.根据配置,是否启动MiniProfiler(ASP.NET MVC的性能分析工具,监控网站性能)
9.1 安装时默认为false,并配置在[dbo].[Setting]表,Name为storeinformationsettings.displayminiprofilerinpublicstore
9.2 配置方法
9.2.1 进入管理页面,进入配置菜单
9.2.2 检索storeinformationsettings.displayminiprofilerinpublicstore,定位该条目,修改Value值
9.2.3 启动效果,在页面左上角可看到该页面执行时间,参考MiniProfiler相关资料
10.记录应用启动日志
10.1 通过依赖注入实例化
10.2 日志写入数据库,表[dbo].[Log]
11.代码如下
protected void Application_Start()
{
//disable "X-AspNetMvc-Version" header name
MvcHandler.DisableMvcResponseHeader = true; //initialize engine context
EngineContext.Initialize(false); bool databaseInstalled = DataSettingsHelper.DatabaseIsInstalled();
if (databaseInstalled)
{
//remove all view engines
ViewEngines.Engines.Clear();
//except the themeable razor view engine we use
ViewEngines.Engines.Add(new ThemeableRazorViewEngine());
} //Add some functionality on top of the default ModelMetadataProvider
ModelMetadataProviders.Current = new NopMetadataProvider(); //Registering some regular mvc stuff
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes); //fluent validation
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new NopValidatorFactory())); //start scheduled tasks
if (databaseInstalled)
{
TaskManager.Instance.Initialize();
TaskManager.Instance.Start();
} //miniprofiler
if (databaseInstalled)
{
if (EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore)
{
GlobalFilters.Filters.Add(new ProfilingActionFilter());
}
} //log application start
if (databaseInstalled)
{
try
{
//log
var logger = EngineContext.Current.Resolve<ILogger>();
logger.Information("Application started", null, null);
}
catch (Exception)
{
//don't throw new exception if occurs
}
}
}
我的NopCommerce之旅(6): 应用启动的更多相关文章
- [转]NopCommerce之旅: 应用启动
本文转自:http://www.cnblogs.com/devilsky/p/5359881.html 我的NopCommerce之旅(6): 应用启动 一.基础介绍 Global.asax 文件 ...
- 我的NopCommerce之旅(8): 路由分析
一.导图和基础介绍 本文主要介绍NopCommerce的路由机制,网上有一篇不错的文章,有兴趣的可以看看NopCommerce源码架构详解--对seo友好Url的路由机制实现源码分析 SEO,Sear ...
- 我的NopCommerce之旅(7): 依赖注入(IOC/DI)
一.基础介绍 依赖注入,Dependency Injection,权威解释及说明请自己查阅资料. 这里简单说一下常见使用:在mvc的controller的构造方法中定义参数,如ICountryServ ...
- 我的NopCommerce之旅(9): 编写Plugin实例
一.基础介绍 ——In computing, a plug-in (or plugin) is a set of software components that add specific abili ...
- 我的NopCommerce之旅(5): 缓存
一.基础介绍 1.什么是cache Web缓存是指一个Web资源(如html页面,图片,js,数据等)存在于Web服务器和客户端(浏览器)之间的副本. 2.为什么要用cache 即 ...
- 我的NopCommerce之旅(4): 定时任务之邮件
一.功能简介 用户购买物品生成订单后,系统将发送邮件提醒给用户 二.操作步骤 后台配置一个系统的默认发送邮箱 启动定时任务,这里包括多个任务,只需要启动邮件任务 查看邮件发送情况 三.数据库分析 [d ...
- 我的NopCommerce之旅(1): 系统综述
一.概述 NopCommerce是一个开源的购物网站,它的特点是Pluggable modular/layered architecture(可插拔模块分层架构) 二.功能特色介绍 1.适配手机端 2 ...
- 我的NopCommerce之旅(3): 系统代码结构分析
一.概述 基于MVC 二.详细描述 \Libraries\Nop.Core 核心类,包括缓存.事件.帮助类.业务对象(订单.客户实体) \Libraries\Nop.Data 数据访问层,采用Enti ...
- 我的NopCommerce之旅(2): 系统环境及技术分析
一.系统环境 IIS7.0 or above ASP.NET 4.5(MVC 5.0) .NET Framework 4.5.1 or above VS 2012 or above 二.架构设计 Pl ...
随机推荐
- sql联合查询去除重复计算总和
1.首先来个联合查询 SELECT 字段1, 字段2, 字段3, 字段4 FROM 表1 INNER JOIN 表2 ON 表1.字段x = 表2.字段x x:代表随意的一个,只要在联合查询的两张表都 ...
- js用正则表达式验证用户和密码的安全性,生成随机验证码
制作了一个表单,表单验证用户.密码.随机验证码 html页面
- [moka摘录]查看邮件是否已被阅读
原文地址:http://www.php100.com/html/php/hanshu/2013/1101/6347.html 查看邮件是否已被阅读 当你在发送邮件时,你或许很想知道该邮件是否被对方已阅 ...
- ahjesus 捕获entity framework生成的sql语句
网上这方面的资料很少,找到一个可以用的 http://code.msdn.microsoft.com/EFProviderWrappers 里面有dll可以下载,有教程,不过是E文的. 在Entity ...
- ahjesus如何在windows下制作适用于mac的u盘启动盘
先用macdrive把U盘格式化成hfs+格式,然后下载原版dmg格式系统,再用ultraISO将dmg转成ISO格式(也可以不用转换),最后用ultraISO里面“启动”--->“写入硬盘映像 ...
- Error message when you try to modify or to delete an alternate access mapping in Windows SharePoint Services 3.0: "An update conflict has occurred, and you must re-try this action"
Article ID: 939308 - View products that this article applies to. Expand all | Collapse all Symptoms ...
- 关于Fragment 不响应onActivityResult的情况分析 (
大家都知道,可以通过使用 startActivityForResult() 和 onActivityResult() 方法来传递或接收参数. 但你是否遭遇过onActivityResult()不执行或 ...
- android res文件夹下面的 values-v11 、 values-v14
values-v11代表在API 11+的设备上,用该目录下的styles.xml代替res/values/styles.xml values-v14代表在API 14+的设备上,用该目录下的styl ...
- UWP开发中的流媒体
写这篇的目的只是为了记住这个东西, win10原生支持HLS了 AdaptiveMediaSourceCreationResult amsResult = await AdaptiveMediaSou ...
- 触发layoutSubviews的条件
1. init初始化不会触发layoutSubviews 2. addSubview会触发layoutSubviews 3. 设置view的Frame会触发layoutSubviews,当然前提是fr ...