The Url method of IPublishContent is sometimes relative and sometimes absolute - umbraco

I have a site in Umbraco 7.7.2 and I need to take the relative Url my pages. I use the method Url and it works on my machine but when I upload my code to my production (on Azure-cloud configuration) it returns the absolute Url instead :|. what should I do?
My site's structure is simple so I have access to those specific pages like this:
var umbraco = new UmbracoHelper(UmbracoContext.Current);
var startPage= umbraco.TypedContentAtRoot().First();
var specificPage= startPage.FirstChild(c => c.IsDocumentType("specificPage"));
var url= specificPage.Url; // returns relative address on my local and absolute url on cloud

The URL it returns depends on the hostnames configured for the site, and the setting in /config/umbracoSettings.config.
In umbracoSettings.config you can set the "useDomainPrefixes" property to true which tells Umbraco to include the domains in the URLs it generates. Is that set n live?
The other thing to check is if the Hostnames are set on the home node in the back office.
When you say relative, do you mean root relative? E.g. /my-page/ as opposed to http://example.com/my-page/? As far as I know Umbraco shouldn't return actual relative links to the page you're on.

Related

Rails route dynamic number of segment

I search to use url like that
/tree/show/folder/subfolder/……/subsubfolder
the content of the page will match the content of a physical folder
The number of segment can be variable obviously since I can show folder then subfolder then another, then another…… As you can imagine it can be long (and of course I'm aware of the limitation of url length)
I precise that I do not want to show public content (like it was already asked here), but to show a page with information relative to a folder
Is it possible ?
You can use wildcard route globbing. Eg:
get 'folders/*subfolders', to: 'folders#index'
This will direct a request for /folders/subfolder/subsubfolder/subsubfolder/ to FoldersController#index, and the called path subfolder/subsubfolder/subsubsubfolder will be accessible in params[:subfolders]
http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments

Relative urls vs Protocol-relative URLs

I am just wondering if I use a relative URL as follows:
"/myfolder"
It will change to
mydomain/myfolder
But does it also maintain if the root is HTTP or HTTPS similar to the "//" approach.
i.e. if the page loading my relative URL /myfolder has HTTPS will this change to
"https://mydomain/myfolder"
tl;dr: Yes.
Relative references are always applied against a base URI (see how).
In HTML5, the document base URL is, in the common case (i.e., no base element, no iframe-srcdoc document, no about:blank), the document's address.
So if you have a document at http://example.com/foo, a link with the relative reference /bar will link to the URL http://example.com/bar. And if the document is at https://example.com/foo, it will link to https://example.com/bar.

Dynamically creating web page (using portion of URL as a variable)

In a site I'm developing I have a page that presents a post based on the variable in the url:
http://www.mywebsite.com?id=18
So this would load the post who's ID is 18 in the mySQL database.
I would like the create the same effect, but with the url being something like:
http://www.mywebsite.com/articles/title-of-article-18/
Would there be a way to create these pages on the fly with dynamic post content, where the url would originally be created by:
"http://www.mywebsite.com/articles/" + postTitle
You are looking for mod_rewrite and rewriting of urls via htaccess.
What it does is it takes patterns from your url, and the htaccess file detects the pattern redirects that to http://www.mywebsite.com?id=18. Users still see the nice url.
The directory /articles/title-of-article-18/ will not actually exist, and the user never really reaches that location because the htaccess secretly changes the url that the server processes.
See
http://en.wikipedia.org/wiki/Rewrite_engine
or a random tutorial I found:
http://www.blogstorm.co.uk/htaccess-mod_rewrite-ultimate-guide/
try url-rewriting
http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/

HttpContext returning only "/"

I have the following two lines of codes in my model, however, both virtual and path have values "\". Where have I gone wrong?
var virtual = VirtualPathUtility.ToAbsolute(HttpContext.Current.Request.ApplicationPath);
var path =HttpContext.Current.Request.ApplicationPath;
From MSDN:
Gets the ASP.NET application's virtual application root path on the server.
So this is the part of the URL's path that is the root of the IIS Web Application the code is running in. The root URL ("http://domain/") is always an IIS Application, so will give "/" as its ApplicationPath.
You perhaps need to convert some child (virtual) folder into an IIS Application to see a longer path result.
Updated from comment:
I want to have the part ":/..."
This information is all available within the properties of Request.Uri. In particular "http" is Uri.Scheme, severname is Uri.Host and the port is Uri.Port (but check Uri.IsDefaultPort to check if you need to specify it).
http://weblogs.asp.net/srkirkland/archive/2009/09/17/a-urlhelper-extension-for-creating-absolute-action-paths-in-asp-net-mvc.aspx

jquery ajax load (full URL)

hi is there a wait to load a full url.?
url= 'http://www.example.com/whatever.php'
$('#selector').load(url); // this way returns null (empty result)
instead of :
url = 'whatever.php'
$('#selector').load(url); // works fine
Some may think whats the difference i want to use this because im using multiple directories. so i could be on a page like...
example.com/dir/
but the dir folder will not have the whatever.php
so anyone has a fix for this that i should always use the full url?
thank you.
You could always use relative paths
putting / before the path will tell the browser to go the root of the page. For your example you could call /whatever.php.
You can also move up one directory at a time. Lets say you are in a page at http://www.example.com/dir/foo/bar.php and want to access something in the dir folder, you could specify ../inTheDir.php to move up one directory or ../../inTheRoot.php to move up two.
This should work for you, but based on your comment it sounds like you have a problem somewhere else since your www. page doesn't seem to respond correctly.
No, there isn't.
If http://www.example.com/ takes longer to load than http://example.com/ then it is probably because you have the DNS record for example.com cached but not the record for www.example.com.
Corrected after having realized a typo changed the meaning of the question.:
This is a case of having a mismatch between the host name the page is loaded from and the host name the Ajaxed resource is requested from. i.e. The Same Origin Policy.
Pick a host name to be canonical, use that one in your requests, and redirect (with a 301 status code) from the other so that people don't go to the wrong one by mistake.

Resources