为什么在“/'应用程序”中获取错误“服务器错误” [英] why getting error "Server Error in '/' Application"

查看:117
本文介绍了为什么在“/'应用程序”中获取错误“服务器错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



以下是我的代码:

Hi All,

Below is my code:

System.Drawing.Image bitmap = (System.Drawing.Image)Bitmap.FromFile(Server.MapPath(@"countimage\2.jpg")); // set image
      //draw the image object using a Graphics object
      Graphics graphicsImage = Graphics.FromImage(bitmap);

      //Set the alignment based on the coordinates
      StringFormat stringformat = new StringFormat();
      stringformat.Alignment = StringAlignment.Far;
      stringformat.LineAlignment = StringAlignment.Far;

      StringFormat stringformat2 = new StringFormat();
      stringformat2.Alignment = StringAlignment.Center;
      stringformat2.LineAlignment = StringAlignment.Center;

      //Set the font color/format/size etc..
      Color StringColor = System.Drawing.ColorTranslator.FromHtml("#fff");//customise color adding
      Color StringColor2 = System.Drawing.ColorTranslator.FromHtml("#fff");//customise color adding
      string Str_TextOnImage = Text2.Value;//Your Text On Image
      string Str_TextOnImage1 = Text3.Value;//Your Text On Image


      graphicsImage.DrawString(Str_TextOnImage, new Font("Lighthouse Personal Use", 50,
      FontStyle.Bold), new SolidBrush(StringColor), new Point(200, 250),
      stringformat);

      graphicsImage.DrawString(Str_TextOnImage1, new Font("Lighthouse Personal Use", 50,
    FontStyle.Bold), new SolidBrush(StringColor), new Point(380, 250),
    stringformat);


      bitmap.Save(Server.MapPath("out3/preview2.Jpg"));



注意:代码在我的本地主机上正常运行但是一旦我尝试将此代码运行到服务器它就显示错误,




Note: Code is running properly on my local host but once i am try to run this code to server it shows an error ,

Server Error in '/' Application.
A generic error occurred in GDI+.




Line 45: 
Line 46: 
Line 47:         bitmap.Save(Server.MapPath("out1/preview3.Jpg"));
Line 48:     }
Line 49:     void img4()



请帮助解决问题,



Aditya Tyagi


please help to shot the issue,

Aditya Tyagi

推荐答案

检查文件夹 - 并停止使用相对路径。它们有失败的倾向,因为页面被移动(或复制)到Web服务器上的不同文件夹。改为使用绝对路径:

Check your folders - and stop using relative paths. They have a tendency to fail because the page is moved (or copied) to a different folder on the webserver. Use an absolute path instead:
Server.MapPath(@"~/Images/out1/preview3.Jpg")



如果你看,你会发现文件夹out1可能不存在,或者如果确实如此,它没有必要的访问权限,让你的应用程序写入它。



但是......一旦你活着你会有更大的问题:当你让两个用户试图同时做同样的事情时,你的固定文件名会引起问题,因为文件将被使用......


If you look, you will find that the folder "out1" probably doesn't exist, or if it does, it doesn't have the required access permissions to let you app write to it.

But...once you "go live" you will have bigger problems: when you get two users trying to do the same thing at the same time, your fixed file names will cause problems because the file will be in use...


这篇关于为什么在“/'应用程序”中获取错误“服务器错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆