简体   繁体   English

用另一台服务器上的绝对路径替换asp:Image相对路径(../../images)

[英]Replace asp:Image relative path (../../images) with absolute path on another server

i have a web application and all of its images are relative path, for example '../../images/logo.png' , 我有一个Web应用程序,其所有图像都是相对路径,例如'../../images/logo.png'

i need to change all of the images in the application to another domain, for example : 'static.domain.com/images/logo.png' 我需要将应用程序中的所有图像更改为另一个域,例如: 'static.domain.com/images/logo.png'

is there a fast way to change all the data ? 有没有一种快速的方法来更改所有数据? of course the long option is to iterate all images and change them manually, 当然,长选项是迭代所有图像并手动更改它们,

In general you should encapsulate relative paths to resources in a code block, like this (using an ASP.NET MVC example as my classic ASP.NET skills are gettting rusty): 通常,您应该将到资源的相对路径封装在代码块中,像这样(使用ASP.NET MVC示例,因为我的经典ASP.NET技能变得生疏了):

<%= Url.Content( "~/images/logo.png" ) %>

To map them to a different path than the default, you can either define a custom route that matches all *.png files (and any other used formats) or introduce your own helper extensions so that you can rewrite the above to something like this: 要将它们映射到与默认路径不同的路径,可以定义一个匹配所有* .png文件(以及任何其他使用的格式)的自定义路由,也可以引入自己的帮助程序扩展名,以便您可以将上述内容重写为如下形式:

<%= Url.Static( "~/images/logo.png" ) %>
  • Replace all occurrences manually 手动替换所有事件
  • Use custom image class, inherited from System.Web.UI.WebControls.Image , to make possible configuration of behavior regarding image path 使用从System.Web.UI.WebControls.Image继承的自定义图像类,可以配置有关图像路径的行为

The easiest is like @TBohnen.jnr said 最简单的就像@ TBohnen.jnr所说

Why don't you do a find and replace (ctrl + H) and replace "../../images/" with 'static.domain.com/images/' risky but should be the easiest? 为什么不查找并替换(ctrl + H)并将“ ../../images/”替换为具有风险的“ static.domain.com/images/”,但这应该是最简单的吗?

you can write a httmhandler for handling .png files, and change their address there. 您可以编写一个用于处理.png文件的httmhandler,然后在此处更改其地址。 another way is to press ctrl+f and find and replace ../../ with your new address in entire solutions which takes a minute. 另一种方法是按ctrl + f组合键,然后在整个解决方案中查找../../并将其替换为您的新地址,这需要一分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM