【编者按】本文出自站外作者 Brij Bhushan Mishra ,Brij 是微软 MVP-ASP.NET/IIS、C# Corner MVP、CodeProject Insider,前 CodeProject MVP,CodeProject Mentor 以及 CodeProject Platinum Member,拥有6年左右的高级开发工程师/架构师经验,自幼酷爱计算机。 1- 内核模式缓存——这是广泛用于程序编写的主要工具之一,可加速 Web 应用程序。可在不同级别使用缓存,具体如下所示。 2- Pipeline 模式(IIS 7+可用)——经典模式和集成模式。 3- 删除不用的模块 通过添加以下代码得到所有模块列表: [C#] 纯文本查看 复制代码 HttpApplication httpApps = HttpContext.ApplicationInstance;
//Get list of active modules
HttpModuleCollection httpModuleCollections = httpApps.Modules;
ViewBag.ModulesCount = httpModuleCollections.Count;
可从 Pipeline 中删除不用的模块。只需在 web.config 中添加下列配置便可删除模块: [C#] 纯文本查看 复制代码 <system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="DefaultAuthentication" />
<remove name="OutputCache" />
<remove name="AnonymousIdentification" />
<remove name="RoleManager" />
modules>
system.webServer>
4- 为所有请求运行所有托管模块--通过以下代码设置对IIS 上所有应用程序有效。
- <modules runAllManagedModulesForAllRequests="true">
5- 切勿在文件夹 c:\inetpub\wwwroot中写入任何内容 6- 删除多余的视图引擎 Application_Start 方法在 Global.asax 内可用。 [C#] 纯文本查看 复制代码 // Removing all the view engines
ViewEngines.Engines.Clear();
//Add Razor Engine (which we are using)
ViewEngines.Engines.Add(new RazorViewEngine());
b) 按照以下方法编写自定义 razor 视图引擎: [C#] 纯文本查看 复制代码 public class MyCustomViewEngine : RazorViewEngine
{
public MyCustomViewEngine()
{
base.AreaViewLocationFormats = new string[] {"~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml"};
base.AreaMasterLocationFormats = new string[] {"~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" };
base.AreaPartialViewLocationFormats = new string[] {"~/Areas/{2}/Views/{1}/{0}.cshtml","~/Areas/{2}/Views/Shared/{0}.cshtml"};
base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml","~/Views/Shared/{0}.cshtml" };
base.MasterLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml","~/Views/Shared/{0}.cshtml" };
base.PartialViewLocationFormats = new string[] {"~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" };
base.FileExtensions = new string[] { "cshtml" };
}
}
本系列后续博文将再介绍5个可用作应用程序性能提升器的技巧。敬请期待! |