1
我想截取的圖像文件的所有請求,但我沒有得到一個辦法做到這一點,我怎麼能算圖像視圖在ASP.NET MVC
一種方法是創建MVC控制器和返回的動作從它所有圖像文件,
public HttpResponseMessage Get(Guid id)
{
var path = HttpContext.Current.Server.MapPath(string.Format("/OriginalImages/{0}.jpg", id));
byte[] fileData = File.Exists(path) ? File.ReadAllBytes(path) : new byte[0];
MemoryStream ms = new MemoryStream(fileData);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
return result;
}
,但它似乎並不像我注意到,圖片訪問請求在15-20毫秒完成,同時通過路徑直接圖像訪問需要5-6毫秒好主意。
我試過使用Owin中間件,但它不會在圖像文件請求上執行。
我該如何做到這一點?我想通過這個增加圖像文件的查看次數。
你可以編輯這個問題,問我「我如何計算圖像視圖」,看看人們提出什麼建議,而不是詢問截取請求,這可能不是你的答案,只提到你真正想做的事情。問你想知道什麼,而不是你認爲答案應該是什麼。 – casey
使用基本控制器文件方法,因爲在這篇文章中:http://stackoverflow.com/questions/186062/can-an-asp-net-mvc-controller-return-an-image。 – KavehG