I'm having a play with the new Services centric API, which looks really sweet and, using my existing abstractions I should be able to switch out quite easilly.
I'm a bit stumped though on how I get a Url in the new API - I can't seem to find anything resembling a NiceUrl() or Url() method or property anyway. Should I be using 'Path'?
Here's an example...
/// /// Gets the content URL. /// /// The node id. /// A nicely formed Url. public string ContentUrl(int nodeId) { return Services.ContentService.GetPublishedVersion(nodeId).Path; }
Is this what I need? I used to have...
/// /// Gets the content URL. /// /// The node id. /// A nicely formed Url. public string ContentUrl(int nodeId) { return Umbraco.Content(nodeId).NiceUrl(); }
yes me too looking for how to get URL from IContent object using new APIs for Umbraco 6? (http://our.umbraco.org/forum/developers/api-questions/38307-How-to-get-NiceUrl-from-IContent-object-in-Umbraco-6)
Not as such. I have big lot of issues(http://our.umbraco.org/forum/developers/api-questions/38322-Issues-with-new-Umbraco-6-APIs) with new APIs in U6
But I have my workaround. Using legacy umbraco.library.NiceUrl(int) . Not sure if new APIs have any good solution for that and also not sure how good or bad this method is from performance point of view.
Remember, you should only use the Services APIs if you need to do tasks on unpublished content. For simple querying in your frontend you should never use the ContentService or MediaService as they always go directly to the database which is not good for your performance.
In macroscripts you could do something like:
@using Umbraco.Web
@{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
}
@umbracoHelper.NiceUrl(yourId)
In a usercontrol you can inherit from UmbracoUserControl:
using System;
using Umbraco.Web.UI.Controls;
namespace YourNamespace
{
public class YourUserControl : UmbracoUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Umbraco.NiceUrl(yourNodeId);
//etc
}
}
}
In a SurfaceController:
using System.Linq;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace YourNamespace
{
public class YourController : SurfaceController
{
[HttpPost]
public ActionResult HandleSomething(YourModel model)
{
Umbraco.NiceUrl(yourNodeId);
//etc.
}
}
}
Apart from NiceUrl there's also NiceUrlWithDomain to get everything.
Late post, but if you are outside the UmbracoContext? How can you figure out the url of a content node? Say if you would like to use umbraco only for editing content and having it send the content somewhere else. Then it would be ideal to be able to get the url of the content node that you get from the contentservice.
I was wondeing how to do this as we use the contentservice and fluentmigrator to make changes to umbraco i.e. adding new nodes or doctypes programatically..
We really need the ability to grab the url but the umbracocontext is null.
I am working on a search for my companies HR website. I am using Examine to perform the search, (Umbraco 6.1.6). When the site was hosted locally on my machine the search had no problems. It has since been moved to 2 servers, which are load balanced. Suddenly the search does not work. The search is performed and the right results are returned. I just cannot get each item to link to the document, (Using NiceUrl(result.Id)). When I hover over each link it is just a '#' symbol.
I have noticed you mentioning things around this area and was wondering if someone could take a look at my cshtml code and offer me any advice?
Any guidance is much appreciated, here is my source code;
@using Examine;
@using Umbraco.Web
@{var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);}
Umbraco 6 - New API - How do I get a URL?
I'm having a play with the new Services centric API, which looks really sweet and, using my existing abstractions I should be able to switch out quite easilly.
I'm a bit stumped though on how I get a Url in the new API - I can't seem to find anything resembling a NiceUrl() or Url() method or property anyway. Should I be using 'Path'?
Here's an example...
Is this what I need? I used to have...
yes me too looking for how to get URL from IContent object using new APIs for Umbraco 6? (http://our.umbraco.org/forum/developers/api-questions/38307-How-to-get-NiceUrl-from-IContent-object-in-Umbraco-6)
Pinal - did you get anything on this?
Not as such. I have big lot of issues(http://our.umbraco.org/forum/developers/api-questions/38322-Issues-with-new-Umbraco-6-APIs) with new APIs in U6
But I have my workaround. Using legacy umbraco.library.NiceUrl(int) . Not sure if new APIs have any good solution for that and also not sure how good or bad this method is from performance point of view.
Remember, you should only use the Services APIs if you need to do tasks on unpublished content. For simple querying in your frontend you should never use the ContentService or MediaService as they always go directly to the database which is not good for your performance.
In macroscripts you could do something like:
In a usercontrol you can inherit from UmbracoUserControl:
In a SurfaceController:
Apart from NiceUrl there's also NiceUrlWithDomain to get everything.
Oh I forgot:
In MVC Razor views you can just do:
Late post, but if you are outside the UmbracoContext? How can you figure out the url of a content node? Say if you would like to use umbraco only for editing content and having it send the content somewhere else. Then it would be ideal to be able to get the url of the content node that you get from the contentservice.
If you use Mortens (sitereactor)example, https://github.com/sitereactor/umbraco-console-example
how can you figure out the url of a content node when you are outside the UmbracoContext?
I'm having exactly the problem Tommy explained.
I'm on a load balancing environment, the ADMIN is on a different machine then the WEB, so the umbracocontext is not available and can't get the URL.
I'm looking for a way to get the node URL from contentservice.
I took a look at the Umbraco source code and I guess I found a solution, this is the code used by Umbraco backend to display the URL:
RoutingContext is an intenral class, so it is not usable, but I changed it to public, recompiled and now the code above works wherever I want :)
Did some test and looks like everything is working perfectly.
Awesome, I will try this out.
I was wondeing how to do this as we use the contentservice and fluentmigrator to make changes to umbraco i.e. adding new nodes or doctypes programatically..
We really need the ability to grab the url but the umbracocontext is null.
Any thoughts?
Did you try with the solution I posted?
I wasn't too keen on recompiling umbraco source seeing as we are using the nuget packages and wanted a smoother upgrade path than previous projects..
Hi,
I am working on a search for my companies HR website. I am using Examine to perform the search, (Umbraco 6.1.6). When the site was hosted locally on my machine the search had no problems. It has since been moved to 2 servers, which are load balanced. Suddenly the search does not work. The search is performed and the right results are returned. I just cannot get each item to link to the document, (Using NiceUrl(result.Id)). When I hover over each link it is just a '#' symbol.
I have noticed you mentioning things around this area and was wondering if someone could take a look at my cshtml code and offer me any advice?
Any guidance is much appreciated, here is my source code;
@using Examine;
@using Umbraco.Web
@{var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);}
@* Get the search term from query string *@
@{var searchTerm = Request.QueryString["search"];}
@{var results = ExamineManager.Instance.Search(searchTerm, true); }
@{if (results.TotalItemCount == 0)
{
<p>No results found</p>
<ul>
<li>Check your spelling</li>
<li>Try using single words</li>
<li>Try searching for a less specific item</li>
</ul>
}
else
{
<ul class="search-results">
@foreach (var result in results)
{
<li>
<a href="@umbracoHelper.NiceUrl(result.Id)">@result.Fields["nodeName"]</a>
</li>
}
</ul>
}
}
is working on a reply...