Reputation: 1401
I am using orchard 1.9 and I am building a service in which I need to get current URL.
I have OrchardServices and from that I can get the URL like so:
_orchardServices.WorkContext.HttpContext.Request.Url.AbsolutePath;
This works like a charm for pages/routes that I have created but when I go to the Login or register page (/Users/Account/LogOn) the absolute URL is / and I can't find anyway to get the URL or at least any indication that I am in the LogOn or Register.
Anyone knows how I could get the full url?
Upvotes: 1
Views: 911
Reputation: 457
If I understand what your're asking, you could use the ItemAdminLink
from the ContentItemExtension
class.
You will need to add references to Orchard.ContentManagement
, Orchard.Mvc.Html
and Orchard.Utility.Extensions
, but then you will have access to the @Html
and @Url
helpers.
From there you will have the ability to get the link to the item using:
@Html.ItemDisplayLink((ContentItem)Model.ContentItem)
The link to the item with the Url as the title using: @Url.ItemDisplayUrl((ContentItem)Model.ContentItem)
And you should get the same for the admin area by using these:
@Html.ItemAdminLink((ContentItem)Model.ContentItem)
@Url.ItemAdminUrl((ContentItem)Model.ContentItem)
They will give you relative paths, e.g. '/blog/blog-post-1'
, but it sounds like you've already got a partial solution for that sorted, so it would be a matter of combining the two.
Although I'm sure there are (much) better ways of doing it, you could get the absolute URL using:
String.Format("{0}{1}", WorkContext.CurrentSite.BaseUrl, yourRelativeURL);
...but if anyone has a more elegent way of doing it then post a comment below.
Hope that helps someone.
Upvotes: 2