asp.net 图片显示 在 运行调试时,显示正常。发布后iis下访问图片不显示。
该模板使用的是母版页,图片地址使用,类似下图 background="<%=Request.ApplicationPath %>/images/main_16.gif"
而实际 IIS下 运行的 图片地址为 http://images/main_16.gif
为何出现此问题,如何修改?
该模板使用的是母版页,图片地址使用,类似下图 background="<%=Request.ApplicationPath %>/images/main_16.gif"
而实际 IIS下 运行的 图片地址为 http://images/main_16.gif
为何出现此问题,如何修改?
解决方案 »
- 图片旋转后显示的问题
- 请教“设计视图不支持创建或编辑框架集”
- 关于javascript里面取控件ID的问题。
- .NET三层的问题
- SQL查询语句小问题
- 关于同步控制问题,另 升星,散分 ,百分感谢你的回复.
- 更换帐号,转分贴,勿回!
- c:\inetpub\wwwroot\WebApplication3\CrystalReport1.rpt 自定义工具“CrystalDecisions.VSDesigner.CodeGen.ReportCodeGenerator”失败
- 刷新问题
- Com组件CListView,CTreeView 放在C#的ASP.NET中如何作用,与C#如何通讯,比如和web控件一样
- 如何显示所有分类 所有页面 包括首页 获取 所有分类 包括三级分类
- 页面多参数传递,如何传
background="~/images/main_16.gif"
显示为右键 源代码 为 ~/images/main_09.gif
改成 ~/的相对路径 连调试都不正常
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE1 {
color: #43860c;
font-size: 12px;
}
.STYLE2 {color: #43860c; font-size: 12px; }
.STYLE4 {
font-size: 12px;
color: #1F4A65;
font-weight: bold;
}a:link {font-size:12px; text-decoration:none; color:#43860c;}
a:visited {font-size:12px; text-decoration:none; color:#43860c;}
a:hover{font-size:12px; text-decoration:none; color:#FF0000;}
a:active {
font-size: 12px;
color: #FF0000;
text-decoration: none;
}
.STYLE7 {font-size: 12}</style>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body onload="MM_preloadImages('<%=Request.ApplicationPath %>/images/main_26_1.gif','<%=Request.ApplicationPath %>/images/main_29_1.gif','<%=Request.ApplicationPath %>/images/main_31_1.gif')">
<form id="form1" runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed;">
<tr>
<td height="9" style="line-height:9px; background-image:url(<%=Request.ApplicationPath %>/images/main_04.gif)"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="97" height="9" style="background-image:<%=Request.ApplicationPath %>/images/main_01.gif" > </td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="47" background="<%=Request.ApplicationPath %>/images/main_09.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="38" height="47" background="<%=Request.ApplicationPath %>/images/main_06.gif"> </td>
<td width="59"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="29" background="<%=Request.ApplicationPath %>/images/main_07.gif"> </td>
</tr>
<tr>
<td height="18" background="<%=Request.ApplicationPath %>/images/main_14.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed;">
<tr>
<td style="width:1px;"> </td>
<td ><span class="STYLE1">
<asp:Literal ID="ltUser" runat="server"></asp:Literal></span></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="155" background="<%=Request.ApplicationPath %>/images/main_08.gif"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="23" valign="bottom"><img src="<%=Request.ApplicationPath %>/images/main_12.gif" width="367" height="23" border="0" usemap="#Map" /></td>
</tr>
</table></td>
<td width="200" background="<%=Request.ApplicationPath %>/images/main_11.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11%" height="23"> </td>
<td width="89%" valign="bottom"><span class="STYLE1">日期:<asp:Literal ID="Literal1"
runat="server"></asp:Literal>
</span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="5" style="line-height:5px; background-image:url(<%=Request.ApplicationPath %>/images/main_18.gif)"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="180" background="<%=Request.ApplicationPath %>/images/main_16.gif" style="line-height:5px;"> </td>
<td> </td>
</tr>
</table></td>
</tr>
</table><map name="Map" id="Map"><area shape="rect" coords="3,1,49,22" onclick="javascript:window.location.href='<%=Request.ApplicationPath %>/Index.aspx';" href="#" /><area shape="rect" coords="52,2,95,21" onclick="javascript:window.history.back();" href="#" /><area shape="rect" coords="102,2,144,21" onclick="javascript:window.history.go(1);" href="#" /><area shape="rect" coords="150,1,197,22" onclick="javascript:window.location.reload();" href="#" /><area shape="rect" coords="210,2,304,20" href="#" /><area shape="rect" coords="314,1,361,23" onclick="javascript:window.close();" href="#" /></map>
<div style="height:637px">
<div style="float:left;width:177;height:637px">
<table width="177" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed">
<tr>
<td height="26" background="<%=Request.ApplicationPath %>/images/main_21.gif"> </td>
</tr>
<tr>
<td height="80" style="background-image:url(<%=Request.ApplicationPath %>/images/main_23.gif); background-repeat:repeat-x;"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="45"><div align="center"><a href='<%= GetUrl(1)%>'><img src="<%=Request.ApplicationPath %>/images/main_26.gif" name="Image1" width="40" height="40" border="0" id="Image1" onmouseover="MM_swapImage('Image1','','<%=Request.ApplicationPath %>/images/main_26_1.gif',1)" onmouseout="MM_swapImgRestore()" /></a></div></td>
<td><div align="center"><a href='<%= GetUrl(2)%>'><img src="<%=Request.ApplicationPath %>/images/main_28.gif" name="Image2" width="40" height="40" border="0" id="Image2" onmouseover="MM_swapImage('Image2','','<%=Request.ApplicationPath %>/images/main_29_1.gif',1)" onmouseout="MM_swapImgRestore()" /></a></div></td>
<td><div align="center"><a href='<%= GetUrl(3)%>'><img src="<%=Request.ApplicationPath %>/images/main_31.gif" name="Image3" width="40" height="40" border="0" id="Image3" onmouseover="MM_swapImage('Image3','','<%=Request.ApplicationPath %>/images/main_31_1.gif',1)" onmouseout="MM_swapImgRestore()" /></a></div></td>
</tr>
<tr>
<td height="25"><div align="center" class="STYLE2"><a href="#">客户管理</a></div></td>
<td><div align="center" class="STYLE2"><a href="#">销售管理</a></div></td>
<td><div align="center" class="STYLE2"><a href="#">统计分析</a></div></td>
</tr>
</table></td>
</tr>
<tr>
<td style="line-height:4px; background:url(<%=Request.ApplicationPath %>/images/main_38.gif)"> </td>
</tr>
<tr>
<td align="center">
<asp:TreeView ID="TreeView1" runat="server">
</asp:TreeView>
</td>
</tr>
</table></td>
</tr>
</table>
</div>
<div style="float:right;height:637px">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="24" background="<%=Request.ApplicationPath %>/images/main_47.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="29" height="24"><img src="<%=Request.ApplicationPath %>/images/main_45.gif" width="29" height="24" /></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="369"><span class="STYLE1">版本 2010V1.0 </span></td>
<td width="814" class="STYLE1"> </td>
<td width="185" nowrap="nowrap" class="STYLE1"><div align="center"><img src="<%=Request.ApplicationPath %>/images/main_51.gif" width="12" height="12" /> 如有疑问请与技术人员联系</div></td>
</tr>
</table></td>
<td width="14"><img src="<%=Request.ApplicationPath %>/images/main_49.gif" width="14" height="24" /></td>
</tr>
</table></td>
</tr>
</table></div>
</form>
</body>
</html>
图片属性错误 http://192.168.1.2:8080/~/images/main_26.gif
多了个 ~/
还是一样 变成 http://images/main_31.gif
正确路径应该为 http://192.168.1.2/images/main_31.gif
在web Config 配置一下
<add key="images" value="~/images"/>然后再代码里读取一下就可以了
ConfigurationManager.AppSettings["images"] + "/main_16.gif";
ConfigurationManager.AppSettings["images"] 中的images为key="images"
background='<%= Page.ResolveUrl("~/images/main_16.gif")%>'
不过 <%= Page.ResolveUrl("~/a.gif") 确实可以解决 谢谢了
结贴