生产服务器上的映像创建

时间:2010-10-31 22:59:29

标签: c# image

我在从数据库文本中动态保存图像时遇到了一个非常烦人的问题。这段代码在我的开发箱上工作正常,但在生产服务器上没有。

以下是我正在尝试做的一个示例:

        private void SaveImage()
    {

       Bitmap objBmpImage = new Bitmap(300, 300);

        int intWidth = 0;
        int intHeight = 0;

        // Create the Font object for the image text drawing.
        Font objFont = new Font("Arial", 12, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);

        // Create a graphics object to measure the text's width and height.
        Graphics objGraphics = Graphics.FromImage(objBmpImage);

        // This is where the bitmap size is determined.
        intWidth = 100;
        intHeight = 100;

        // Create the bmpImage again with the correct size for the text and font.
        //objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));

        // Add the colors to the new bitmap.
        objGraphics = Graphics.FromImage(objBmpImage);

        //bounding box
        RectangleF rectf = new RectangleF(0, 0, 295, 295);

        // Set Background color
        objGraphics.Clear(Color.White);
        objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
        objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
        objGraphics.DrawString("Test", objFont, Brushes.Black, rectf);
        objGraphics.Flush();

        objBmpImage.Save(@"***SERVER PATH HERE****");
        Response.Write("Image saved completed");
    }

服务器路径具有网络服务写入权限

1 个答案:

答案 0 :(得分:0)

检查您的代码在哪个帐户下运行(类似于System.Environment.UserName),并确保它是您期望的名称。

默认情况下,模拟已打开,用户可能没有给定文件夹的写入权限。代码也可以在匿名用户帐户下运行(即,如果您有表单身份验证/ anonoymous用户)。

在任何情况下,您都需要验证用户是否有权在服务器磁盘上创建映像,并在具有权限的帐户下完成写入。即您可以显式模拟某个特定帐户并运行写入该帐户下磁盘的代码。

同时检查生产应用程序池是否在您期望的帐户下运行。即它可能(也可能不应该)在网络服务帐户下运行。