HTML IMG和ASP.NET的图像和相对路径 [英] HTML img and ASP.NET Image and relative paths

查看:255
本文介绍了HTML IMG和ASP.NET的图像和相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是引用图像中的ASP.NET IIS上部署直播?

的正确方法

在开发和生产以下工作:

 < ASP:ImageButton的ID =ibnEdit=服务器的OnClick =ibnEdit_Click的ImageUrl =〜/ App_Themes文件/默认/图像/ one.png可见=假工具提示=编辑/>

以下任一不工作:(为什么不呢?)

 < IMG SRC =〜/ App_Themes文件/默认/图像/ two.gif/>

在开发,但不是在生产中的以下工作:

 < IMG SRC =../ App_Themes文件/默认/图像/ two.gif/>


解决方案

如果你想使用一个普通的 IMG 标记和的路径,你可以添加 =服务器进入标签作为一个属性(像普通服务器控件)和路径将得到解决。例如:

 < IMG SRC =〜/ App_Themes文件/默认/图像/ two.gif=服务器/>

有关你的第二个组成部分,是出现在多个页面的图像../参考,例如用户控件或母版页(ETC),这样你可能会使用它在不同的文件夹级别...

What is the correct way to reference an image in ASP.NET for live deployment on IIS?

The following works in dev and production:

<asp:ImageButton ID="ibnEdit" runat="server" OnClick="ibnEdit_Click" ImageUrl="~/App_Themes/Default/images/one.png" Visible="false" ToolTip="Edit" />

The following doesn't work in either: (why not?)

<img src="~/App_Themes/Default/images/two.gif" />

The following works in dev but not in production:

<img src="../App_Themes/Default/images/two.gif" />

解决方案

If you want to use a regular img tag with the ~ path, you can just add runat="server" into the tag as an attribute (like regular server controls) and the path will be resolved. e.g:

<img src="~/App_Themes/Default/images/two.gif" runat="server" /> 

For your second part, is the ../ image reference appearing on more than one page, for example a user control or master page (etc) such that you might be using it at different folder levels...

这篇关于HTML IMG和ASP.NET的图像和相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆