#眉標=MVC、ASP.NET、Controller #副標=ASP.NET網站開發與應用(4) #大標=ASP.NET MVC Framework與網站效能最佳化 #作者=文/圖 王寧疆 ===<反灰>============= [OutputCache(Duration=60, VaryByParam="id")] public ActionResult ShowPhoto(int id) {  NorthwindDataContext dc = new NorthwindDataContext();  var picture = from c in dc.Categories   where c.CategoryID==id   select c.Picture;  ImageResult result = new ImageResult(picture.First().ToArray(), "image/jpeg");  return result; } ================ ===<反灰>============= [OutputCache(Duration=60, VaryByParam="None")] public class CategoriesController : Controller { } ================ ===<反灰>============= ================ ===<反灰>============= Appcmd.exe set config -section:urlCompression -doStaticCompression:true -doDynamicCompression:true ================ ===<反灰>============= Appcmd.exe set config "網站名稱" -section:urlCompression -doStaticCompression:true -doDynamicCompression:true ================ ===<反灰>============= Appcmd.exe set config -section:httpCompression -[name='gzip'].staticCompressionLevel:9 -[name='gzip'].dynamicCompressionLevel:4 ================ ===<反灰>============= appcmd.exe set config -section:system.webServer/httpCompression /+"[name ='deflate',doStaticCompression='True',doDynamicCompression='True', dll='%Windir%\system32\inetsrv\gzip.dll']" /commit:apphost ================ ===<反灰>============= ================ ===<反灰>============= ================ ===<反灰>============= background-image: url(圖6的圖檔); display:block; height:16px; left:50%; margin-left:-8px; margin-top:-8px; overflow-x:hidden; overflow-y:hidden; position:absolute; text-indent:-99999px; top:50%; width:16px; ================ ===<反灰>============= from p in context.Products where p.UnitPrice <= MaximumPrice select p ================ ===<反灰>============= public Func> CheapProducts = CompiledQuery.Compile((NorthwindDataContext context, decimal MaximumPrice) => from p in context.Products where p.UnitPrice <= MaximumPrice select p); ================ ===<反灰>============= NorthwindDataContext dc = new NorthwindDataContext(); dataGridView1.DataSource=CheapProducts(dc, Convert.ToDecimal(txtUnitPrice.Text)).ToList(); ================ ===<反灰>============= NorthwindDataContext dc = new NorthwindDataContext(); dc.Log = Console.Out; //將DataContext的物件的執行動作顯示到主控台視窗 var query = from c in dc.Customers where c.City == "London" select c; //查詢居住在London的客戶的LINQ敘述 foreach (var c in query) //第一次執行LINQ敘述 Console.WriteLine(c.CompanyName); Console.WriteLine("\n"); foreach (var c in query) //再執行一次LINQ敘述 Console.WriteLine(c.CompanyName); ================ ===<反灰>============= SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0] WHERE [t0].[City] = @p0 -- @p0: Input NVarChar (Size = 6; Prec = 0; Scale = 0) NOT NULL [London] SqlProvider\AttributedMetaModel Around the Horn Consolidated Holdings Eastern Connection North/South Seven Seas Imports SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0] WHERE [t0].[City] = @p0 -- @p0: Input NVarChar (Size = 6; Prec = 0; Scale = 0) NOT NULL [London] SqlProvider\AttributedMetaModel Around the Horn Consolidated Holdings Eastern Connection North/South Seven Seas Imports ================ ===<反灰>============= NorthwindDataContext dc = new NorthwindDataContext(); dc.Log = Console.Out; //設定將DataContext類別的物件的執行動作顯示到主控台視窗 var query = from c in dc.Customers where c.City == "London" select c; //查詢居住在London的客戶的LINQ敘述 var listCusts = query.ToList(); //結果存到listCusts,當做快取記憶體 foreach (var c in listCusts) //第一次執行LINQ敘述 Console.WriteLine(c.CompanyName); Console.WriteLine("\n"); foreach (var c in listCusts) //再執行一次LINQ敘述 Console.WriteLine(c.CompanyName); ================ ===<反灰>============= SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0] WHERE [t0].[City] = @p0 -- @p0: Input NVarChar (Size = 6; Prec = 0; Scale = 0) NOT NULL [London] SqlProvider\AttributedMetaModel Around the Horn Consolidated Holdings Eastern Connection North/South Seven Seas Imports Around the Horn Consolidated Holdings Eastern Connection North/South Seven Seas Imports ================