Developer forum

Forum » Development » Going backwards from customized URL

Going backwards from customized URL


Reply
Hi,

From a given customized URL in plain text, I would like to resolve the product id of the product displayed on this address. Since DW core is able to do that, I'd assume that we could to that in our custom code as well. Is there an API approach I could use, or could you provide me with some pointers to implement a similar functionality?

BR.
Lars

Replies

 
Reply
Hi Lars!

You don't need to translate customized url. When your custom code is executed, DW processes customized URL to normal URL: http://yoursite/default.aspx?id=10&productid=NNN&variantid=MMM&langid=Lang1

So productid can be accessible by Request.QueryString["productid"]   // C# style :)

Best regards,
Vladimir
 
Reply
 Hi Vladimir,

Thanks, I'm aware of that, but I would like to go the other way around and take a URL, perhaps stored in a database or typed in manually, and resolve the clean product ID from that. Imagine I have a list of URLs like the following:

http://mysite.dk/Products/Lawnmowers/Lawnmower_XYZ.aspx

This URL contains three hidden values:

 - ID (Products)
 - GroupID (Lawnmowers)
 - ProductID (Lawnmover XYZ)

On my list I'd like to find the ProductID of the Lawnmower XYZ product in the same way Dynamicweb does it when trying to make sense out of a URL.

So I'm looking for a method in the API that does that or some pointers to how you did that in the core.

BR.
Lars
 
Reply
Hi Lars!
That example of how DW do this, altough slightly simplified...  You can run it in custom module, to see how it work
           URLParser p = new URLParser();
           string url = p.parseParameters("http://mysite.dk/Products/Lawnmowers/Lawnmower_XYZ.aspx");
I hope, this helps you...

Best regards,
Vladimir
 
Reply
 Hi Vladimir,
 
Could you zip or rename the file? You get a 403.1 on a .cs file in a Files sub directory because there's no execute permissions in that directory.

Thanks.

BR.
Lars
 
 
Reply
archive
 
Reply
Hi Vladimir,

I wasn't able to make your example work, but based on your API references I was able to make an example that worked with my project.

Is there a provider for page URLs also?

Thanks:)

BR.
Lars
 
Reply
There is no provider for pages, but you can use PageURLHash instead:
        public int getPageID(string url)
        {
            int pageID = 0;
            Hashtable PageURLHash = (Hashtable)HttpContext.Current.Application.Item("PageURLHash");

            if (PageURLHash.ContainsKey(requestPath))
                pageID = (int)PageURLHash.Item(pagePart);
            else
            {
                string fullPath = url.Replace(".aspx", "");
                string modulePart = fullPath.Substring(url.LastIndexOf('/'));
                string pagePart = fullPath.Replace(modulePart, "");

                while (pagePart.Contains("/"))
                {
                    if (PageURLHash.ContainsKey(pagePart + ".aspx"))
                    {
                        pageID = (int)PageURLHash.Item(pagePart + ".aspx");
                    }
                    else
                        pagePart = pagePart.Replace(pagePart.Substring(pagePart.LastIndexOf('/')), "");
                }
            }

            return pageID;
        }


Best regards,
Vladimir
 
Reply
 Excellent, thanks:)

 

You must be logged in to post in the forum