Removing Image Source URL Parameter Extras

Yoyo Bubble asked on July 23, 2018 21:05

Hello ,

I'm currently attempting to remove a handful of url parameters that are getting added to my image source tags when I use a custom macro I made to grab an image from the media library.

The source currently looks something like this:


How do I remove the "?width=2560&height=1726&ext=.jpg" parameters from the end of the URL?

This is an attempt to start using the 51degrees device detection method to create the parameters based on the user's device.

Any ideas?

Recent Answers

Trevor Fayas answered on July 24, 2018 14:56

well, the quick and dirty is just take the resulting URL string and do a "TheUrl?WithParams".Split("?")[0] as if there is a ? (and should only be 1) it will take the first section, if no ? then it still will result the first section (the whole string).

If you provide the custom macro you're using to generate this though it would help us understand how you are getting the above and will be easier to help you out. There are many ways to generate a media url.

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on July 26, 2018 10:44

Kentico has a specific helpers class to work with URLs - URLHelper. This class has RemoveQuery method. So, you can use that method in your custom macro, something like this:

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.