I have an image control inside a repeater. I would like to exclude/ignore a parameter in the imageurl property, because the path(source image) do not have this parameter in the name, but I still want to show the parameter in url. And I can’t rename all the images, as there are a lot. Hope it make sense.
Here is an example.
It is for SEO. Original path
- /product/0001_100_00_KK00_F02.png
What I want to show in imageurl
- /product/0001_100_00_KK00_F02.png/Tv-Sony-lcd-black-bravia-KDL-26V4500
OR
- /product/0001_100_00_KK00_F02/Tv-Sony-lcd-black-bravia-KDL-26V4500.png
<asp:Repeater ID="rptImages" runat="server"> <ItemTemplate> <asp:Image ID="Image1" ImageUrl='<%# Eval("Url") %>' runat="server" /> </ItemTemplate> </asp:Repeater>
And codebehind
rptImages.DataSource = Images.Select(s => new { Url = s }); rptImages.DataBind();
This works fine for the original path. But when I add /Tv-Sony-lcd-black-bravia-KDL-26V45000 to the end of url the images is not found(of course).
So how do I add an extra parameter to the imageurl, but get the image control to ignore this and still find the image path?
Does anyone have any ideas of how to resolve this problem
You can achive that with URL rewriting. Add global.asax file to your project and use some kind of rewriting logic like this.
This will work but will also rewrite all request.paths which contains”.png” because of “if (currentPath.IndexOf(“.png”) > -1)”
It is safer to include few more conditioning.