在链接中使用绝对路径时出现的开发问题(由于友好的 url)

发布于 2024-07-11 04:16:52 字数 227 浏览 8 评论 0原文

我使用 urlrewriter.net 来实现友好的 url。 当我重写时,我有时会使用子文件夹。

我发现自己在图像和链接方面遇到问题,并且 ~ 符号对我不起作用。 读了一下之后,我发现我不是唯一一个遇到这个问题的人,他们建议使用完整路径“www.website.com/images/x.jpg”等。 现在,我无法开发和质量检查,因为所有链接都指向我真正的在线网站。

我能做些什么?

I using urlrewriter.net to implement friendly urls.
When I did the rewriting I used subfolders on occasions.

I found myself having problems with images and links and the ~ sign wasn't working for me. After reading a bit I found out that I'm not the only one with that problem and they recommended using full path "www.website.com/images/x.jpg" etc.
Now, I can't develop and QA because all of the links go to my real online website.

What can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳 2024-07-18 04:16:52

如果 URL 前缀是您唯一关心的问题,您是否考虑过在 web.config 中为 URL 前缀添加一个键,然后以这种方式动态生成图像的路径?

通过这样做,您可以在完成后轻松地将所有代码迁移到生产环境,然后只需更新 web.config 以将所有内容指向正确的服务器。

If the URL prefix is your only concern, have you thought about adding a key to your web.config for the URL prefix and then dynamically generate the path to your images that way?

By doing this you can easily migrate all the code up to production when finished, and then simply update the web.config to point everything to the proper server.

无所的.畏惧 2024-07-18 04:16:52

~ 仅适用于 ASP.NET Web 控件,不适用于标准 HTML 控件。

当您的内容页面(位于子文件夹中)引用应用程序根目录中的母版页时,也会出现类似的问题。 您需要在 MasterPage 中使用图像和超链接控件,因为文件是从内容页面的位置引用的。

HyperLink;

~ only works with ASP.NET Web Controls, not standard HTML controls.

A similar problem is when you have content pages (located in subfolders) referencing a masterpage in the application root. You need to use Image and Hyperlink controls in the MasterPage since the files are referenced from the location of the content page.

<asp:Image ID="Image1" runat="server" ImageUrl="~/images/Test.png" AlternateText="" />

<asp:HyperLink ID="HyperLink1" runat="server"NavigateUrl="~/Test.aspx">HyperLink</asp:HyperLink>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文