How to create friendly url in asp.net 2

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

what solution?

+1


source to share


3 answers


You need to make sure you use the "~ /" path notation in your images, and make sure they are all server controls with runat = "server". Otherwise, image URLs will not be rewritten.

For example, if you have a page that is being rewritten with:

/Item/Bicycle.aspx

to

/Item.aspx?id=1234



Then what happens is that the link to the image looks like this:

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

      

will break. So you should instead 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 embed as much as possible in your .css files.

+1


source


You can try using a url relay like IIRF .

With IIRF, you can use regular expressions to parse the incoming url and then post it to the desired location.



They have examples based on how to do it all in IIRF download.

0


source


What solution? Use the new routing engine in .NET 3.5 that is running in an MVC project and has been promoted offline. :)

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

0


source







All Articles