2013-03-21 152 views
0

我在asp.net page.Here是代码图像上传到服务器..asp.net图片上传到服务器

代码

protected void Button2_Click1(object sender, EventArgs e) 
     { 

      //resimyolu = "~/r/" + FileUpload1.FileName; 
      FileUpload1.SaveAs(Server.MapPath("~/r/a.png")); 
      FileUpload1.SaveAs("d:/upresim/a.png"); 
      Image1.ImageUrl = "~/r/a.png"; 

     } 

的 'R' 的文件夹在我project.when图像文件夹我的图片添加到在运行时的“R”的文件夹,它的工作原理成功地在本地IIS,但是当我发表我的项目,其驻留在服务器(远程服务器)上的网页被打开在浏览器中,但是当我点击按钮2到客户端的图像(其中客户端用户从他的电脑中选择)添加到出现下一个错误的项目..

Runtime Error 
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off". 
+0

你的错误没有说太多。将您的customErrors模式设置为remoteOnly。然后,您可以从服务器运行此页面并查看正确的错误。 – nunespascal 2013-03-21 10:57:19

+0

这里是正确的异常信息:System.Web.HttpException:SaveAs方法被配置为需要有根路径 – 2013-03-21 11:07:08

+0

我买了你的时间,谢谢 – 2013-03-21 11:21:42

回答

0

由于错误信息提示,禁用你的web.config中的自定义错误,看看有什么问题。

<configuration> 
    <system.web> 
     <customErrors mode="Off"/> 
    </system.web> 
</configuration> 
+0

我做的:这里是excaption:异常详细信息:System.Web.HttpException:另存方法被配置为需要一个根路径,并且路径'〜/ r/a.png'没有根。 – 2013-03-21 11:02:51

+0

我买了你的时间,谢谢 – 2013-03-21 11:23:30

0

问题是这条线。

FileUpload1.SaveAs("d:/upresim/a.png"); 

更改为有帮助。

FileUpload1.SaveAs("d:\\upresim\\a.png"); 

避免使用硬编码等的路径,如果你的代码。更换机器时您将遇到问题。 Server.MapPath总是一个更好的方式去。如果您不想保存在您的网络目录中,则应始终从配置中获取基本路径。

+0

但tihis线运行succesfull.the问题是FileUpload1.SaveAs(使用Server.Mappath( “〜/ R/a.png”));因为它无法发现那位“R”文件夹服务器 – 2013-03-21 11:18:21

+0

感谢您的想法 – 2013-03-21 11:20:35

+0

我买了你的时间,谢谢 – 2013-03-21 11:24:36