使用Server.MapPath后,网页中引用相对路径的图片打不开

todaywlq 2006-02-24 11:41:19
我用Server.MapPath("虚拟目录")获取到虚拟目录的物理路径后,再找开虚拟目录中的网页,网页上的图片都打不开了,网页上的图片是用相对路径引用的,查看网页上的图片属性发现路径不对

正确的应该是
http://IP/虚拟目录/image/aaa.gif

但现在是
http://IP/image/aaa.gif
...全文
331 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
half_bucket 2006-02-27
  • 打赏
  • 举报
回复
说说你用哪种编码方式?gb还是unicode?
todaywlq 2006-02-27
  • 打赏
  • 举报
回复
问题解决了,不是Server.MapPath的问题,
是Response.Redirect(Server.UrlEncode(strUrl));有问题
改为Response.Redirect(strUrl);就好了。

为什么对url编码后相对目录就不对了
todaywlq 2006-02-27
  • 打赏
  • 举报
回复
还是不行,楼上的能不能说一下
Server.MapPath("~");
怎么用。
webdiyer 2006-02-25
  • 打赏
  • 举报
回复
Server.MapPath("~");
todaywlq 2006-02-25
  • 打赏
  • 举报
回复
自己顶
todaywlq 2006-02-24
  • 打赏
  • 举报
回复
有没有人知道呀?帮帮忙,很急呀
todaywlq 2006-02-24
  • 打赏
  • 举报
回复
加分了,各位帮帮忙
todaywlq 2006-02-24
  • 打赏
  • 举报
回复
代码如下
//路径
custCMD = new SqlCommand("SELECT url FROM pic_xm WHERE id="+ strId, Conne);
myReader = custCMD.ExecuteReader();
string strUrl="";
if(myReader.Read())
{
if(myReader.IsDBNull(0)==false)
strUrl=myReader.GetString(0);
else
strUrl="";
}
else
strUrl="";
myReader.Close();

Conne.Close();

int intIndex = strUrl.IndexOf("\\");
string strXnml;
if(intIndex > 0)
{
strXnml = strUrl.Substring(0,intIndex);
}
else
{
strXnml = "";
}
string strDir = Server.MapPath(strXnml);
string a = Server.MapPath(".");
if(System.IO.File.Exists(strDir + "\\" + strUrl.Substring(intIndex + 1,strUrl.Length - intIndex - 1)))
{
Response.Redirect(Server.UrlEncode(strUrl));
}
else
{
Response.Redirect("error.aspx?Mess=nofile");
}
heyafeng 2006-02-24
  • 打赏
  • 举报
回复
把代码贴上来,帮你改

YaFeng Studio
欢迎大家进行.NET技术交流
todaywlq 2006-02-24
  • 打赏
  • 举报
回复
还没解决,各位高手帮帮我
todaywlq 2006-02-24
  • 打赏
  • 举报
回复
数据没问题
可以打开strUrl指向的网页,但网页上的图片打不开

还有
去掉 string a = Server.MapPath(".");这句代码也是一样的。

各位再帮帮忙
half_bucket 2006-02-24
  • 打赏
  • 举报
回复
string strDir = Server.MapPath(strXnml);
string a = Server.MapPath(".");
————————————————
Server.mapPath不适用于“.”或“..”的相对路径语法,只能用于同级目录,所以可能出错。
lhcoolhacker 2006-02-24
  • 打赏
  • 举报
回复
可能情况如下:
1:数据库获取的数据为空
2:int intIndex = strUrl.IndexOf("\\");中intIndex < 0,建议采用断点调试,或者Response.Write(intIndex),看看该值为何
meixiaofeng 2006-02-24
  • 打赏
  • 举报
回复
虚拟目录会没有?

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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