这段代码在本机调试正常,在服务器不行,为什么?

来源:百度知道 编辑:UC知道 时间:2024/06/28 00:14:49
protected void btnModify_Click(object sender, EventArgs e)
{
//验证图片格式
string newPhotoName = "";

newPhotoName = WebUtility.GetRandFileName() + ".jpg";

System.Drawing.Image imgOutput = System.Drawing.Bitmap.FromFile(this.flpImgPath.PostedFile.FileName);
System.Drawing.Image imgOutput2 = imgOutput.GetThumbnailImage(100, 120, null, IntPtr.Zero);
imgOutput2.Save(System.Web.HttpContext.Current.Server.MapPath("~/images/userfaces/" + newPhotoName), System.Drawing.Imaging.ImageFormat.Jpeg);
imgOutput.Dispose();
imgOutput2.Dispose();

//this.flpImgPath.PostedFile.SaveAs(Server.MapPath("~/images/userfaces/") + newPhotoName);

MainMethods.RedirectMsg_UserPage("修改成功!", this.Request.RawUrl, MainMethods.MsgFaceType.SuccessFace);

}
谢谢大家的关注,我想我找到原因了,正在改改看,我try了一下,只得到了一个文件的地址。所以这个地址在本机是存在

有可能是路径问题 请仔细查看 局对路径或相对路径
还有个可能如果
在其他地方使用了 openFileDialog 控件 也可能造成默认路径错误
也可能 权限问题

建议把~去掉,因为可能服务器设置不允许使用~获得根目录.
换成../images(或者相应的目录)试试,

出现本机调试正常,在服务器不行的原因可能是文件夹的权限问题啦,给你要操作的文件夹加上权限.

给服务器的图片文件夹的ASP.NET用户添加个修改的权限