Developer forum

Forum » Feature requests » Be able to convert URL til friendly URL in custom handler

Be able to convert URL til friendly URL in custom handler

Morten Fink Eriksen
Reply

Hi Support

 

I have a problem where i am trying to use:

 

Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(InternalLink)

 

In a custom handler, but i keep on getting "Object reference not set to an instance of an object.", is it not possible to do this in a custom handler or any other external code that is not in a page context?

If its not possible, then i would really like to suggest this as a feature.

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Morten

 

In what context are you calling the method? And can I have you post the entire stack trace?

 

It requires a httpcontext and maybe also a pageview context. But if we can see the context in which you are trying, we can change the method.

 

BR Nicolai

 
Morten Fink Eriksen
Reply

Hi Nicolai

 

I have made a custom handler (IHttpHandler) for some custom instant search and in its "ProcessRequest(HttpContext context)" method i am trying to convert the URL to friendly URL's.

 

The method has a HttpContext, but something seems to be missing for me to be able to convert the url. So maybe the httpcontext isn't enough?

 

UPDATE:

 

[NullReferenceException: Object reference not set to an instance of an object.]
   Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(String internalLink) +304
   FricyklerModules.EcomSearch.ProcessRequest(HttpContext context) +1267
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +624
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +269

 
Nicolai Høeg Pedersen
Reply

A httphandler does not have a asp.net page context which is required by the pageview. So that is why you cannot make it work - the method is depending on the pageview that is depending on a page.

 

Is it just Default.aspx?ID URLs you need - or do you also have ecommerce Things in?

 

BR Nicolai

 
Morten Fink Eriksen
Reply

Hi Nicolai

 

I also have some ecom specific stuff yes.

 

Is there some way around this?

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

The easy way would be enabling the the "Ensure unique path [] Forward to link (301 Moved Permanently) " option in the management center for customized URLs.

 

That will change the URL to the friendly one if you link to the unfriendly version.

 

If you need to make the URLs without a context is apart from that not easy. It needs the context of domains, area, page etc. to be able to give you bullet proof URLs...

 

But you can use Dynamicweb.Frontend.UrlProviders.Handler.GetUrl() for looking up the eCommerce part of the URL (ProductID, GroupID and VariantID) and you can use the page index of the pageview to find the page part of the URL.

BR Nicolai

 

 

 

Votes for this answer: 1
 
Morten Fink Eriksen
Reply

Ok.. ill try and use the things you suggested in order to generate the URL

 

Thanks

 

Best Regards

Morten Fink Eriksen

 
Morten Fink Eriksen
Reply

This doesn't seem to do what i am intending, maybe i didn't explain it right... i want to be able to take a GroupID and ProductID and convert it to the friendly version URL based on parameters i deliver, not from what it finds in the current URL.

 

Is this possible?