Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 15:51
    Ismail Mayat
    0

    NiceUrl problem

    I am using umbraco 6.1.5 and I have the following code

    string resultsPage = library.NiceUrl(Constants.Umbraco.ResultsPage);
    
     serverUrl = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + resultsPage + "?"
                                    + Constants.Web.QueryString.RecordId + "=" + guid;
    

    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

  • Stephen 767 posts 2273 karma points c-trib
    Oct 30, 2013 @ 16:05
    Stephen
    0

    Is NiceUrl returning "http://mysite/results/" or "http/mysite/results/"? I can explain the first one, not the second...

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 30, 2013 @ 16:08
    Ali Sheikh Taheri
    1

    Hi Ismail,

    can you use any of these methods to see if it is still the same ?

    Umbraco.NiceUrl(Constants.Umbraco.ResultsPage)
    Umbraco.NiceUrlWithDomain(Constants.Umbraco.ResultsPage)
    
  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 16:14
    Ismail Mayat
    0

    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

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 30, 2013 @ 16:22
    Ali Sheikh Taheri
    0

    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.

    Cheers

    Ali

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 16:27
    Ismail Mayat
    0

    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

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 30, 2013 @ 16:43
    Ali Sheikh Taheri
    0

    there is no easy way to use it in standalone class as far as I know

    few ways I know:

    1. Pass UmbracoHelper to the constructor of the Class
    2. Pass UmbracoHelper to the method as parameter.
  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 30, 2013 @ 16:48
    Ali Sheikh Taheri
    0

    just figured out they both use umbraco assembly, but they are 2 different classes.

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 30, 2013 @ 17:01
    Ali Sheikh Taheri
    0

    can you try this?

    using Umbraco.Web;
    
    public class Class1
    {
        public Class1()
        {
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
            var url = umbracoHelper.NiceUrl(1234);
        }
    }
    
  • Stephen 767 posts 2273 karma points c-trib
    Oct 30, 2013 @ 17:31
    Stephen
    0

    @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?

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 17:41
    Ismail Mayat
    0

    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

  • Stephen 767 posts 2273 karma points c-trib
    Oct 30, 2013 @ 17:50
    Stephen
    0

    @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.

     

  • karen 186 posts 461 karma points
    Sep 17, 2014 @ 23:26
    karen
    0

    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.

  • Stephen 767 posts 2273 karma points c-trib
    Sep 18, 2014 @ 08:30
    Stephen
    0

    That would be UrlProviderMode in the WebRouting section of the umbracoSettings.config file, so...

    ...
    <web.routing urlProviderMode="value" />
    </settings>

    With value being AutoLegacy (default, relative or absolute + respects useDomainPrefixes), Relative (always, never absolute), Absolute (always, never relative), Auto (relative or absolute).

Please Sign in or register to post replies

Write your reply to:

Draft