asp.net网站应用程序中的相对URL [英] relative url in asp.net website applications

查看:72
本文介绍了asp.net网站应用程序中的相对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图片,我想以相对格式使用它的src属性

I have an image that I want to use it's src attribute in relative format

当我的网站URL为http://localhost/时,我曾经使用此代码访问此图像文件:

when my website URL was http://localhost/ I used to use this code to access this image file:

<img alt="something" src="/Files/pic.png">

但是现在我必须将应用程序添加到我的站点并将站点URL更改为http://localhost/mysite.

But now I have to add an application to my site and change my site URL to http://localhost/mysite.

现在我的所有图像都没有加载到该站点中,因为路径仍然是http://localhost/Files/pic.png而不是http://localhost/mysite/Files/pic.png

Now none of my images load in this site because the path is still http://localhost/Files/pic.png not http://localhost/mysite/Files/pic.png

如何将我的根URL(/)更改为http://localhost/mysite/?

how can I change my root URL (/) to http://localhost/mysite/?

谢谢

推荐答案

在服务器控件中使用代字号~以使用相对路径.

Use tilde ~ in a server control to use a relative path.

<asp:Image runat="server" ID="myImage" ImageUrl="~/Files/pic.png" />

这篇关于asp.net网站应用程序中的相对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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