How to create friendly url's in asp.net 2

纵然是瞬间 提交于 2019-12-11 05:15:34

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/278856/how-to-create-friendly-urls-in-asp-net-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!