无法在 .NET Web 应用程序中找到图像
我将页面的一些 html 内容保存到数据库中。根据情况,我从数据库中获取内容的html并将其放入页面。
示例内容:
<p>
Test Content
<img src="~/images/test.jpg" />
</p>
问题是~
没有按我的预期工作。如何配置 ~
作为 Web 应用程序任何文件的绝对路径,例如 .css、.aspx 中的文件,以便将其呈现为 www.test.com/images/test .jpg ?
根据答案:
我有一个内容位于数据库中,因此即使我添加它们 runat=server,图像' src 或锚点' href 也会呈现为 html 内容。所以我应该做的是,在将字符串放入 aspx 页面之前,我应该运行一个函数并将此内容作为参数提供给它。然后将网站的绝对路径放在任何 src 或 href 标签中,其中包含 ~ 。这可以通过正则表达式来完成。
I keep some html content of the pages to the database. According to situation I get the html of content from the database and put it to the page.
Example content:
<p>
Test Content
<img src="~/images/test.jpg" />
</p>
The problem is ~
doesnt work as I expected. How do I configure ~
to work as an absolute path of the web application any of files e.g. in .css, .aspx so it will be rendered as www.test.com/images/test.jpg
?
According to answers:
I have a content that is on the database so the image' src or anchor' href is rendered just as an html content even if I add them runat=server. So what I should do is, before putting string to the aspx page, I should run a function and give this content as a parameter to it. Then put the absolute path of website any src or href tags where a ~ in it. This can be done by regex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 CSS 内容链接,您可以遵循下面的相对路径 HTML 指南,
对于 .aspx 页面中的 HTML,您可以使用,
For CSS content linking you can follow relative path HTML guidance below,
For HTML in .aspx pages you can use,
只需删除“~”,您始终可以使用“/”指向网站的根目录,
所以只需
just remove the "~" you can always point to the root of the website by using "/"
So just
请添加
-img 的属性
Please add the
-attribute to the img