我目前正在運行專用服務器的網站,但希望在未來使用Microsofts Azure雲平臺進行擴展,但是我不確定我的代碼的certin部分是否可以在azure上正常工作。在Azure中生成圖像asp.net
該網站包含一個項目與每個項目的圖像庫。 圖像存儲在sqlserver數據庫中。
我創建了一個http處理程序,將圖像緩存到磁盤並將請求重定向到圖像(如帖子結尾處所示)。
圖像被保存到ASP.NET應用程序中名爲「imagecache」的虛擬目錄中。 (即〜/ imagecache /)。
由於Web應用程序將在Azure平臺上的許多虛擬機實例中運行,因此圖像需要在實例之間共享對嗎?
所以我的問題真的是..什麼是實現我已經有的最好的方式是與天青兼容?
感謝
圖片根代碼..
public class getimage : IHttpHandler {
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void ProcessRequest (HttpContext context) {
try
{
string uniqueid = "";
if(context.Request.QueryString["id"]) uniqueid = context.Request.QueryString["id"].ToString();
string dir = "~/imagecache/";
string image_target_path = dir + "image-file-" + uniqueid + ".png";
byte[] data = null;
context.Response.ContentType = "image/png";
if (!System.IO.File.Exists(context.Server.MapPath(image_target_path)))
{
if (context.Request.QueryString["id"] != null)
{
// get image data from the database
data = ImageHelper.getDatabaseImageDataByID(Convert.ToInt32(uniqueid));
using (System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(data)))
{
// save image to disk in the virtual dir
img.Save(context.Server.MapPath(image_target_path));
}
}
else
{
// set a sample image if no id is set
image_target_path = "~/images/noimage.png";
}
}
// redirect request to image file
context.Response.Redirect(image_target_path, false);
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
public bool IsReusable {
get {
return false;
}
}
}