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
Developer forum
E-mail notifications
Going backwards from customized URL
Posted on 20/04/2011 14:28:12
Replies
Posted on 21/04/2011 02:29:10
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
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
Posted on 26/04/2011 09:09:19
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
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
Posted on 27/04/2011 07:26:46
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
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
Posted on 27/04/2011 08:52:28
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
Posted on 28/04/2011 10:11:30
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
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
Posted on 29/04/2011 03:29:12
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
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
Posted on 29/04/2011 11:32:30
Excellent, thanks:)
You must be logged in to post in the forum