0

类似于我的其他问题之一,但我需要澄清。

我有一个 Web 应用程序,其中多个用户将同时打开。在应用程序中,将在其中一个应用程序文件夹中绘制图像,如下所示,保存,然后添加到页面上的图像控件。

Bitmap image = new Bitmap(Server.MapPath("~") + "/Assets/img/timegrid.jpg");
Graphics graphics = Graphics.FromImage(image);
Pen p = new Pen(Color.Blue, 5); 
//draw on image
graphics.DrawLine(p, aPoint, bPoint); 

//save new image
image.Save(Server.MapPath("~") + "/Assets/img/newtimegrid.jpg");
imgGrid.ImageUrl = "~/Assets/img/newtimegrid.jpg";

每个用户的新图像看起来都不同。但是,我担心用户 A 会看到用户 B 的 newtimegrid.jpg 而不是他自己的,因为每个用户都保存到相同的文件名。我听说过使用通用图像处理程序并且我已经阅读了一些解决方案here,但我仍然不明白如何使用它,或者如果我做了一个如何调用它,或者这甚至是一个解决方案我的问题。任何帮助,将不胜感激。

4

1 回答 1

1

我建议您将 userID 保留在会话中,并在路径中使用此 id 来唯一标识每个用户图像路径的图像路径。

您可以先检查用户的路径是否已存在。

string strDirPath = Server.MapPath("~") + "/Assets/img/ + Session["UserID"].ToString();

if(Directory.Exists(strDirPath))
{
     Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
     //your code here
}
else
{
     DirectoryInfo CreateDirectory(strDirPath);
     Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
     //your code here
}
于 2012-05-24T17:27:10.060 回答