Niceurl is returning the second one. I am assuming for the first one if in the umbracoSettings you have usedomainprefix set to true you get full url? In my instance its set to false. One thing to note the live instance goes through a load balancer so im not sure if that is causing an issue?
Ali, not easily as i cannot debug on the live client server.
If you are using load balancer I would suggest to set up an appSetting in web.config for your doamin and read the value from the web.config rather than HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
one more enhancement would be to use Umbraco rather than umbraco.library to take advantage of new API.
using Umbraco.Web;
public class Class1
{
public Class1()
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var url = umbracoHelper.NiceUrl(1234);
}
}
@Ismail: by default NiceUrl is configured to return a relative url where possible, else an absolute url.
Say you have domain "foo.com" configured. If you navigate http://foo.com and get the nice url of a page under that node, you should get a relative url eg /path/to/page. But if you navigate http://bar.com and get the nice url of a page under the foo node, you will get an absolute url eg http://foo.com/path/to/page.
Making sense?
I think you are seeing differences between dev and production because the hostnames are not configured the same and/or you don't access the page with the same url.
On dev and live hostnames are set correctly. On live there is a load balancer and firewall that it comes through and i suspect this is causing the issue so domain is wrong and hence we get barfed url. Will investigate further.
@Ismail: if the infrastructure mangles the request so that the domain perceived by Umbraco is not the expected domain, then yes that might cause an issue because Umbraco is going to return absolute urls to try to correct the situation.
However, if that was really the case, there is a config setting that tells Umbraco to stop even trying to create clever urls, and always render relative urls. Let me know, I need to find out where that setting is as it has moved between version.
With value being AutoLegacy (default, relative or absolute + respects useDomainPrefixes), Relative (always, never absolute), Absolute (always, never relative), Auto (relative or absolute).
NiceUrl problem
I am using umbraco 6.1.5 and I have the following code
On my dev server all works fine. However on my live server I get the following url which is not correct:
http://mysitehttp/mysite/results/?recordId=a4344d3e-90f1-4ce1-9335-03ece5ec2f80
Anyone seen this before? It looks like niceurl is returning http/mysite/results/ which obviously is not correct it should just return /results
My dev server is win2k3 iis6 and live server is win2012 iis8
Any ideas
Regards
Ismail
Is NiceUrl returning "http://mysite/results/" or "http/mysite/results/"? I can explain the first one, not the second...
Hi Ismail,
can you use any of these methods to see if it is still the same ?
Stephan,
Niceurl is returning the second one. I am assuming for the first one if in the umbracoSettings you have usedomainprefix set to true you get full url? In my instance its set to false. One thing to note the live instance goes through a load balancer so im not sure if that is causing an issue?
Ali, not easily as i cannot debug on the live client server.
Regards
Ismail
If you are using load balancer I would suggest to set up an appSetting in web.config for your doamin and read the value from the web.config rather than
HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
one more enhancement would be to use
Umbraco
rather thanumbraco.library
to take advantage of new API.Cheers
Ali
Ali,
Just tried Umbraco.NiceUrl and it cannot find the method? Am i missing references also this is in class not razor etc.
Regards
Ismail
there is no easy way to use it in standalone class as far as I know
few ways I know:
UmbracoHelper
to the constructor of the ClassUmbracoHelper
to the method as parameter.just figured out they both use
umbraco
assembly, but they are 2 different classes.can you try this?
@Ismail: by default NiceUrl is configured to return a relative url where possible, else an absolute url.
Say you have domain "foo.com" configured. If you navigate http://foo.com and get the nice url of a page under that node, you should get a relative url eg /path/to/page. But if you navigate http://bar.com and get the nice url of a page under the foo node, you will get an absolute url eg http://foo.com/path/to/page.
Making sense?
I think you are seeing differences between dev and production because the hostnames are not configured the same and/or you don't access the page with the same url.
Again, making sense?
Stephan,
On dev and live hostnames are set correctly. On live there is a load balancer and firewall that it comes through and i suspect this is causing the issue so domain is wrong and hence we get barfed url. Will investigate further.
Regards
Ismail
@Ismail: if the infrastructure mangles the request so that the domain perceived by Umbraco is not the expected domain, then yes that might cause an issue because Umbraco is going to return absolute urls to try to correct the situation.
However, if that was really the case, there is a config setting that tells Umbraco to stop even trying to create clever urls, and always render relative urls. Let me know, I need to find out where that setting is as it has moved between version.
What is this setting?
I need it to force to render only relative urls (server is behind a reverse proxy and that is messing things up)
UmbracoSettings.config has
<useDomainPrefixes>false</useDomainPrefixes>
but that doesn't seem to be it.
That would be UrlProviderMode in the WebRouting section of the umbracoSettings.config file, so...
With value being AutoLegacy (default, relative or absolute + respects useDomainPrefixes), Relative (always, never absolute), Absolute (always, never relative), Auto (relative or absolute).
is working on a reply...