Urlresolver.geturl() returns null

Vote:
 

Hi,

I am using two web projects in a single solution, the Urlresolver.geturl() returns the URL for one web project but in another project, it returns null.

I tried in follwing ways,

urlResolver.GetUrl(ContentReference contentLink)

urlResolver.GetUrl(IContent content)

urlResolver.GetUrl(ContentReference contentLink, string language)

But I got null.

How to resolve this.

#195171
Jul 17, 2018 7:02
Vote:
 

Checked that the site URLs and host names are setup correctly in Admin mode?

#195216
Jul 17, 2018 22:50
Vote:
 

Thank you Johan.

I will check and confirm with you.

#195230
Jul 18, 2018 9:39
Vote:
 

Is this Page browseable? This usually happens if you only created the Model and the Controller for the Page Type but no view associated with it. 

#195247
Jul 18, 2018 15:44
Vote:
 

Hi Johan,

I do the same what you advise, But still, I got the null response.

Actually, I have a separate service project in which I can't get the URL.

The main project has contains the controllers and views, there the URL resolver.geturl() workes fine.

Is this necessary to have the views and controllers for getting the Url in my separate project. or

Is there any api is available to get the Url, without using controllers and views.

I tried, Urlhelper and UrlResolver but both gave null responce.

#195256
Jul 18, 2018 17:49
Vote:
 

hi,

it shouldn't require mvc type project (where views and controllers are) to get link of the content. in what context are you calling GetUrl()? is it episerver scheduled job or during just a normal web request (controller calls service lib to do the work)?

#195270
Jul 19, 2018 6:00
Vote:
 

Thanks, Valdis.

I am trying to use it inside the APIController(AJAX call).

Adding to that, While including the Controllers and views it works well, When excluding it, returns null.

In my case without controllers and views can we get the URL?

Kindly suggest and advise.

#195285
Jul 19, 2018 11:23
Vote:
 

hi,

it will NOT work in api controller out of the box. as api controller is called "directly" getting or posting to the api endpoint. in order for the episerver to resolve whole context, request needs to be "normal" - like accessing episerver page (then epi kicks in and setups whole execution context including all routing stuff and such).

if you could describe a bit more in details the usage scenario (how and why you need to get content url) we could figure out what would be the best way to get that url.

i've implemented in back in days that client side is passing in content id from back to the api controller (like episerver page itself generates content id in markup and clientside takes it and passes back to api controller). then used content repositopry to fetch the page. sounds hacky, but that's one of the ways how to "restore" epi context in non-epi request.

#195286
Jul 19, 2018 11:30
Vote:
 

Hi Valdis,

Thank you very much for your advice.

Actually, I try to get the URL of the page data.

By using content id I just build the URL directly without using API.

Thank you.:)

 

#195351
Jul 20, 2018 15:20
Sanjay Kumar - Nov 08, 2019 14:18
Hi Vetrivel,

In my case, I was getting URLs null when I was calling API end-point. After investigation I found the Controller and View were not defined for the passing ContentReference item within the Urlresolver.GetUrl() method. So try this approach.
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.