如何在 asp.net 2 中创建友好的 url

发布于 2024-07-08 20:25:32 字数 90 浏览 10 评论 0原文

我尝试使用 IHttpModule 并成功地转换了 url, 但我的所有图像都返回路径错误(全部通过新的 url 目录)。

解决办法是什么?

I tried using the IHttpModule and managed to convert the urls just fine,
but all of my images returned path error (all going through the new url directory).

whats the solution?

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

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

发布评论

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

评论(3

此岸叶落 2024-07-15 20:25:32

您需要确保在图像上使用“~/”路径符号,并确保它们都是带有 runat='server' 的服务器控件。 否则图像 url 将不会被重写。

例如,如果您有一个页面从

/Item/Bicycle.aspx

重写为

/Item.aspx?id=1234

那么将会发生这样的图像引用:

<img src='images/something.gif' />

将被破坏。 因此,您必须执行以下操作:

<asp:image imageurl='~/images/something.gif' runat='server' id='img1'/>

或者您可以对图像使用绝对路径。 或者您可以将尽可能多的内容推送到 .css 文件中。

You need to make sure that you use the "~/" path notation on your images and make sure that they are all server controls with runat='server'. Otherwise the images urls won't get rewritten.

For example if you have a page that gets rewritten from:

/Item/Bicycle.aspx

to

/Item.aspx?id=1234

Then what will happen is that an image reference like this:

<img src='images/something.gif' />

will break. So instead you have to do something like this:

<asp:image imageurl='~/images/something.gif' runat='server' id='img1'/>

Alternatively you can use absolute paths for your images. Or you can push as much as possible into your .css files.

往昔成烟 2024-07-15 20:25:32

您可以尝试使用 URL 重写器,例如 IIRF

使用 IIRF,您可以根据需要使用正则表达式来解析传入的 URL,然后将其发送到正确的位置。

他们在 IIRF 下载中内置了有关如何执行所有操作的示例。

You can try using a URL rewriter such as IIRF.

With IIRF you can use regular expressions to parse the incoming URL as you wish, then send it to the right place.

They have examples built in on how to do all that in the IIRF download.

撩动你心 2024-07-15 20:25:32

解决办法是什么? 使用 .NET 3.5 中的新路由引擎,该引擎在 MVC 项目中启动并提升到独立状态。 :)

如果 Keltex 的建议不能解决您的具体问题,请查看 ResolveUrl 和 ResolveClientUrl。

What's the solution? Use the new routing engine in .NET 3.5 that started in the MVC project and got elevated to stand-alone status. :)

If Keltex's suggestion doesn't solve your specific problem look at ResolveUrl and ResolveClientUrl.

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