Get url of Orchard default pages - url

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?

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.

Related

Missing the middle or a URL

I was wondering if there was a way to find a URL when I am missing the middle. For example, I know that the beginning will be https://welldressedwolf/products/
and the end will be pretty-things but I do not know the middle portion.
With javascript you can get the full URL using window.location.href
After that you can remove the parts you dont want and you will have the middle.
More info: https://www.w3schools.com/js/js_window_location.asp
If you're looking to manually look up the address of a page, you could do so with a google search that specifies the site.
Try a site specific google search using something like the following:
"pretty things" site:welldressedwolf.com

How to set url map routing for all pages?

I want to get a name in url and then redirect to original page for example:
<facebook.com/mat/default.aspx> to <facebook.com/default.aspx>
with map routing i can do this like :
routes.MapPageRoute("userName_map", "{userName}/default","~/default.aspx");
but i cant do this for every page.i want a solution for all page
what can i do?
If they all go to "~/default.aspx", you can do this using a wildcard:
routes.MapPageRoute("userName_map", "{*userName}", "~/default.aspx");
The asterisk * tells it that anything past {userName}/ is to apply to this rule.
Hope this helps! Good Luck!

Codeigniter _remap function

Please help I want to use first URI segment into my CodeIgniter website.
Like when I open these url they opens my profile:
http://www.facebook.com/buddyforever
or
http://www.myspace.com/zarpio
How can I do this with CodeIgniter? I checked _remap function but first coming controller how to hide controller?
You can do this using the URL routing of codeigniter...
If you want your URL to be http://www.mydomain.com/zarpio and you want it to refer to your_controller, then do the following.
/config/routes.php
$route['(.*)'] = "your_controller/$1"; // Now, `zarpio` will be passed to `your_controller`
You can access it in your controller like this...
$my_name = $this->uri->rsegment(2);
However I do not suggest this way of configuring URLs. A better way would be...
$route['users/(.*)'] = "your_controller/$1";
This way, you're just renaming your controller name your_controller to users.
If you want to access profile of a user, you can do it like this...
$route['users/profile/(.*)'] = "another_controller/method/$1";
$route['users/(.*)'] = "your_controller/$1";
Consider the order of routing. Since you wrote users/(.*) in your route, it will match users/zarpio as well as users/profile/zarpio, and route both of them to your_controller/$1, which in the case of profile will give you a 404 page not found error. That is why you need to write users/profile/(.*) before users/(.*) in your routing configuration.
More information in codeigniter URI class documentation

Rails route rewriting

I think this is an easy question. I am using this useful Flash Document Reader called FlexPaper. I have it embedded in one of my Show pages. But when I click the a link on their tool bar to show the document in a new browser, it points to the following link:
http://example.com/intels/FlexPaperViewer.swf?ZoomTime=0.5&FitPageOnLoad=false&PrintEnabled=false&SwfFile=%2FPaper.swf
which doesn't work, I get the following error:
ActiveRecord::RecordNotFound in IntelsController#show
Couldn't find Intel with ID=FlexPaperViewer
but if I remove the "intels" from the path so the url looks like:
http://example.com/FlexPaperViewer.swf?ZoomTime=0.5&FitPageOnLoad=false&PrintEnabled=false&SwfFile=%2FPaper.swf
It works fine.
My question is what is the best way to handle this? Can you write a route that rewrites a url that starts with intels/FlexPaperViewer.swf and remove the intels prefix? What would that look like?
Is there a better option?
Juat a thought, how about placing the FlexPaperViewer.swf inside public/intels folder?
So the directory structure will be
<project-directory>/public/intels/FlexPaperViewer.swf
Doing this will make the link correct. It seems to be easier to do it this way.
Hopefully it helps.
EDIT
Another alternative will be to see how the link was generated, maybe there is a parameter that you can set when you embed the FlexPaper.
I am not aware of any route modification that can do what you want. Maybe someone else can help on this.

Grails g:paginate tag and custom URL

I am trying to use g:paginate in a shared template where depending on the controller, url changes e.g.
For my homepage url should be : mydomain[DOT]com/news/recent/(1..n)
For search Page: www[DOT]mydomain[DOT]com/search/query/"ipad apps"/filter/this month
and my g:paginate looks like this:
g:paginate controller=${customeController} action=${customAction} total:${total}
For the first case, I was able to provide controller as 'news' and action as 'recent' and mapped url /news/recent/$offset to my controller.
But for the search page, I am not able to achieve what I want to do. I have a URL mapping defined as /search/$filter**(controller:"search",action:"fetch")
$filter can be /query/"ipad apps"/filter/thismonth/filter/something/filter/somethingelse.
I want to be able to show the url as above rather than
?query="ipad apps"&filter=thismonth&filter=something&filter=somethingelse.
I believe I can pass all the parameters in params attribute of g:paginate but that will not give me pretty URL.
What would be the best way to achieve this? Please feel free to ask questions If i missed anything.Thanks in advance.
Ok. figured this out. Hope this helps someone.
Set ${customAction} ='' and this query string 'filter/thismonth/filter/something/filter/somethingelse' was passed with 'params' alltribute.
Thanks

Resources