从根运营商相对路径("〜")在code后面的地址 [英] Relative path from a root operator ("~") address in code behind

查看:79
本文介绍了从根运营商相对路径("〜")在code后面的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像Image.ImageUrl服务器控件使这很容易,但是想实现背后的IMG HTML控件在code同样的事情并不那么简单。

Server controls like Image.ImageUrl make this very easy, but trying to achieve the same thing in code behind to an IMG html control is not that straightforward.

例如使用ASP:图像服务器控件设置ImageUrl属性为〜/图片/ test.jpg放在正常工作,无论哪个目录我把code在(asp.net转变波浪目录相对的。 )

For example using an Asp:Image server control and setting ImageUrl property to "~/Images/Test.jpg" works fine no matter what directory i place the code in. (asp.net transforms tilde directory to relative)

我怎样才能做到在后面code中的一样吗?当我试图创建一个HTML IMG控制?

How can i do the same in code behind? when i am trying to create an HTML IMG control?

推荐答案

使用Page.ResolveUrl(〜/.....\");

Use Page.ResolveUrl("~/.....");

这篇关于从根运营商相对路径("〜")在code后面的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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