对路径“C:Inetpubwwwrootnutideimagespics6662.gif”的访问被拒绝

jolin_sy 2011-06-22 04:43:16
对路径“C:Inetpubwwwrootnutideimagespics6662.gif”的访问被拒绝
我后台是这么写的 为什么他会把我的\号都给弄没了啊?
string path = Server.MapPath("~");
string folder = "images\\LmImg\\";
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(path + folder + filename);
...全文
224 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mic_Gary 2013-10-16
  • 打赏
  • 举报
回复
没看明白楼主是怎么解决的
jolin_sy 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 taomanman 的回复:]
string folder = System.Web.HttpContext.Current.Server.MapPath("/") + "/images/LmImg".Replace("/", "\\") + "\\";

你为什么要替换呢?

string folder = System.Web.HttpContext.Current.Server.MapPath("~/") + "/……
[/Quote]

谢谢。。我也是直接调的方法 着急没细看 3Q
暖枫无敌 2011-06-22
  • 打赏
  • 举报
回复
string folder = System.Web.HttpContext.Current.Server.MapPath("/") + "/images/LmImg".Replace("/", "\\") + "\\";

你为什么要替换呢?

string folder = System.Web.HttpContext.Current.Server.MapPath("~/") + "/images/LmImg/";
jolin_sy 2011-06-22
  • 打赏
  • 举报
回复
权限是开放的啊 但是 他提示对路径“这里是路径但是所有的/ 都没了 ”的访问被拒绝

为什么我一上传就给我吧 所有/ 都给弄没啦?


protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
try
{

if (FileUpload1.FileName != "")
{
switch (FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1).ToLower())
{
case "jpg":
break;
case "gif":
break;
case "png":
break;
default:
ScriptManager.RegisterStartupScript(Page, this.GetType(), "script", "alert('请上传gif或者jpg的图片')", true);
return;
}

if (FileUpload1.PostedFile.ContentLength > 100 * 1024 )
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "script", "alert('文件最大100K')", true);
return;
}

CS.BLL.LMShenQingShenHe bll = new CS.BLL.LMShenQingShenHe();
bool bl = bll.Existss(nickname);
if (bl)
{
string folder = System.Web.HttpContext.Current.Server.MapPath("/") + "/images/LmImg".Replace("/", "\\") + "\\";
//string path = Server.MapPath("~/images/LmImg/");
//string folder = "images\\LmImg\\";
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(folder + filename);

//string path = Server.MapPath("~/images/LmImg/");
//string filename = FileUpload1.FileName;
//FileUpload1.SaveAs(path + filename);

CS.Model.LMShenQingShenHe model = new CS.Model.LMShenQingShenHe();
CS.Model.LMShenQingShenHe lmModel = bll.GetModels(nickname);
model.id= lmModel.id;
model.NickName = nickname;
model.userID = userID;
model.ShenQingLeiXing = 3;
model.Zname = Zname.Value;
model.telephone = DianHua.Value;
model.phone = ShouJi.Value;
if (TxQQ.Value != "" && TxQQ.Value != null)
{
model.QQ = TxQQ.Value;
}
model.MSN = MSN.Value;
model.WzBkName = WZName.Value;
model.WzBkDiZhi = WZdiZhi.Value;
model.ShenQingTime = DateTime.Now;
if (QiTa.Value == "" || QiTa.Value == null)
{
model.SchoolName = area2.Value;
}
else
{
model.SchoolName = QiTa.Value;
}

model.SchoolShenFen = area1.Value;
model.SchoolXiaoQu = XueXiaoDiQu.Value;
model.SchoolEnglish = XueXiaoEnglish.Value;
model.ZhiYe = size_1.Value;
model.NianJi = NianJi.Value;
model.BiYeTime = BiYeTime.Value;
model.ZhuanYe = ZhuanYe.Value;
model.SchoolZhiWu = ZhiWu.Value;
model.NameID = nameID.Value;
model.SchoolDiZhi = XueXiaoDiZhi.Value;
model.YouBian = YouBian.Value;
model.TuPian = filename;
model.ShenQingJieGuo = 1;
bll.Update(model);
Page.ClientScript.RegisterStartupScript(typeof(Page), "2", "alert('申请成功,请等待审核结果');window.location.href='account.aspx'", true);

}
else
{
string folder = System.Web.HttpContext.Current.Server.MapPath("/") + "/images/LmImg".Replace("/", "\\") + "\\";
//string path = Server.MapPath("~/images/LmImg/");
//string folder = "images\\LmImg\\";
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(folder + filename);
CS.Model.LMShenQingShenHe model = new CS.Model.LMShenQingShenHe();

model.NickName = nickname;
model.userID = userID;
model.Zname = Zname.Value;
model.telephone = DianHua.Value;
model.phone = ShouJi.Value;
if (TxQQ.Value != "" && TxQQ.Value != null)
{
model.QQ = TxQQ.Value;
}
model.MSN = MSN.Value;
model.ShenQingLeiXing = 3;
model.WzBkName = WZName.Value;
model.WzBkDiZhi = WZdiZhi.Value;
model.ShenQingTime = DateTime.Now;
if (QiTa.Value == "" || QiTa.Value == null)
{
model.SchoolName = area2.Value;
}
else
{
model.SchoolName = QiTa.Value;
}
model.SchoolShenFen = area1.Value;
model.SchoolXiaoQu = XueXiaoDiQu.Value;
model.SchoolEnglish = XueXiaoEnglish.Value;
model.ZhiYe = size_1.Value;
model.NianJi = NianJi.Value;
model.BiYeTime = BiYeTime.Value;
model.ZhuanYe = ZhuanYe.Value;
model.SchoolZhiWu = ZhiWu.Value;
model.NameID = nameID.Value;
model.SchoolDiZhi = XueXiaoDiZhi.Value;
model.YouBian = YouBian.Value;
model.ShenQingJieGuo = 1;
model.TuPian = filename;
bll.Add(model);


Page.ClientScript.RegisterStartupScript(typeof(Page), "2", "alert('申请成功,请等待审核结果');window.location.href='account.aspx'", true);
}

}
else
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "script", "alert('请选择您要上传的图片');", true);
}


}
catch (Exception ex)
{
Response.Write("<script>alert('失败!" + ex.Message + "');</script>");
return;
throw;
}

}
cjh200102 2011-06-22
  • 打赏
  • 举报
回复
用楼上的试试, 外加开放权限

[Quote=引用 4 楼 taomanman 的回复:]

C# code

string path = Server.MapPath("~/images/LmImg/");
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(path + filename);
[/Quote]
LONG332949572 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 imfor 的回复:]
string path = Server.MapPath("~/images/LmImg/");
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(path + filename);
[/Quote]
+1
暖枫无敌 2011-06-22
  • 打赏
  • 举报
回复
最关键的是你的该文件夹要在开发写权限,要不然无法保存的。
暖枫无敌 2011-06-22
  • 打赏
  • 举报
回复

string path = Server.MapPath("~/images/LmImg/");
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(path + filename);


imfor 2011-06-22
  • 打赏
  • 举报
回复
string path = Server.MapPath("~/images/LmImg/");
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(path + filename);
md5e 2011-06-22
  • 打赏
  • 举报
回复
估计你用的是虚拟目录
Server.MapPath("/你的网站文件夹/")
子夜__ 2011-06-22
  • 打赏
  • 举报
回复
Server.MapPath("./")

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧