car*_*r_3 1 asp.net image-generation azure azure-storage
我目前正在运行一个专用服务器的站点,但希望将来使用Microsofts Azure云平台进行扩展,但我不确定我的代码的certin部分是否适用于azure.
该网站包含一个项目库,每个项目都有一个图像.图像存储在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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里的简单答案是将图像存储从SQL移动到Azure存储Blob.然后,可以将这些blob的容器公开并通过URL访问,而无需您充当缓存层的中介.
但是,如果您仍希望您的应用程序通过http处理程序充当该中介,那么您仍然可以使用1.3 SDK实现该目标.本节介绍了完整的IIS,它允许您在Web角色中配置虚拟目录和http处理程序.
但我真的建议你看一下使用公共可读的blob容器.它为您提供了相同级别的功能,可显着降低工作量.您甚至可以将这些技术结合起来,投入一小撮Azure AppFabric缓存,以便在需要时添加更多灵活性和功能.
| 归档时间: |
|
| 查看次数: |
1078 次 |
| 最近记录: |