This seems to be a very similar issue to at least 20 other tickets on the Forum going back at least a year, all of which point to there being some issue with NiceUrl.
We have recently taken over a site from another agency that was built using Umbraco 4.0.2 and we have upgraded it to 4.7.1.1 this has involved changing all the XSLT to the new format and lot of refactoring along the way.
The issue we have is within a custom URL Rewriting method, skipping a few steps this does the following:
var newNode = new umbraco.NodeFactory.Node(int.Parse(nodeId.Value)); ourNiceUrl = newNode.NiceUrl;
And we have also tried to change this to work in this way:
var myUrl = library.NiceUrl(int.Parse(nodeId.Value));
Both of the above should return a nice URL but instead they both return a #
This is where it gets weird... if we publish the page we are trying to access and attempt to access the same page again, it works as expected.
However, if we restart IIS ( or re-build our project and deploy the new code, essentially restarting the site ) we get back to the issue of NiceUrl returning a # symbol.
Does anyone have any ideas bar us having to debug the core?
Yes, it's currently configured to run using the Network Service account.
If you step through, the newNode object exists, it's the right page node, but the NiceUrl is '#'
As you can see from the screen shot below...
But, as mentioned above, as soon as we re-publish the page, everything just magically starts to work, I have a dent in my head from banging the wall so much with this one!
Seen that issue before on our sites... unless we reference a property on the object before using NiceUrl property... pretty weird... So, in code, try to get a property first and then try NiceUrl on the object. Does it work then? Ok, this is not a solution, but in these rare cases, i use umbraco.library.NiceUrl(node.Id) to generate the url.
We have also tried the Umbraco.library.NiceUrl(node.id) ( I did mention that in the first post :) ) but that also returns the '#'
Hence it's a real head banger,
What I don't get, is why does re-publishing a page make things suddenly work?! Another weird thing, is that if you re-publish the site it does not fix things, if you publish the parent node it does not fix things... you have to actually publish the individual page that is not working and then ping.... it works.
As you can see I also left in the default behaviour, which is to return a '#' if there is an error, so we now all know where these '#' symbols are coming from :)
The error that is being logged is:
System.NullReferenceException: Object reference not set to an instance of an object. at umbraco.library.niceUrlJuno(Int32 nodeId, Int32 startNodeDepth, String currentDomain, Boolean forceDomain) in g:\2 - Projects\Umbraco471Source\umbraco\presentation\library.cs:line 441
at umbraco.library.NiceUrlFetch(Int32 nodeID, Int32 startNodeDepth, Boolean forceDomain) in g:\2 - Projects\Umbraco471Source\umbraco\presentation\library.cs:line 524
at umbraco.library.niceUrlDo(Int32 nodeID, Int32 startNodeDepth, Boolean forceDomain) in g:\2 - Projects\Umbraco471Source\umbraco\presentation\library.cs:line 426
at umbraco.library.NiceUrl(Int32 nodeID) in g:\2 - Projects\Umbraco471Source\umbraco\presentation\library.cs:line 372
So, as you can see the NiceUrl method calls niceUrlDo... which calls NiceUrlFetch.... which in turn calls NiceUrlJuno... which is where our error is occuring.
And the error is coming from the UmbracoContext.Current as it is equal to NULL !!?!
So... long story short... by adding the following to the top of the NiceUrl method:
if (UmbracoContext.Current == null) UmbracoContext.Current = new UmbracoContext(HttpContext.Current);
And a similar check in the requestModule.cs - Application_Request method:
// create the Umbraco context if (UmbracoContext.Current == null) UmbracoContext.Current = new UmbracoContext(httpContext);
This fixes this bug :)
Can anyone see any issues with those changes as everything seems to work fine?
The reason for the issue is that the UmbracoContext does not get created until the Application_Request method fires and this is AFTER the URL Redirect module tries to do it's re-directing and hence there is no Context.
NiceUrl returns a # instead of the correct URL
Hi All,
This seems to be a very similar issue to at least 20 other tickets on the Forum going back at least a year, all of which point to there being some issue with NiceUrl.
We have recently taken over a site from another agency that was built using Umbraco 4.0.2 and we have upgraded it to 4.7.1.1 this has involved changing all the XSLT to the new format and lot of refactoring along the way.
The issue we have is within a custom URL Rewriting method, skipping a few steps this does the following:
And we have also tried to change this to work in this way:
Both of the above should return a nice URL but instead they both return a #
This is where it gets weird... if we publish the page we are trying to access and attempt to access the same page again, it works as expected.
However, if we restart IIS ( or re-build our project and deploy the new code, essentially restarting the site ) we get back to the issue of NiceUrl returning a # symbol.
Does anyone have any ideas bar us having to debug the core?
Best regards,
Chris
Chris,
Are permissions correct and is the site running in its own app pool and is the account the app pool is running under the one that has folder access?
Regards
Ismail
Hi Ismail,
Yes, it's currently configured to run using the Network Service account.
If you step through, the newNode object exists, it's the right page node, but the NiceUrl is '#'
As you can see from the screen shot below...
But, as mentioned above, as soon as we re-publish the page, everything just magically starts to work, I have a dent in my head from banging the wall so much with this one!
Cheers, Chris
Chris,
Seen that issue before on our sites... unless we reference a property on the object before using NiceUrl property... pretty weird... So, in code, try to get a property first and then try NiceUrl on the object. Does it work then? Ok, this is not a solution, but in these rare cases, i use umbraco.library.NiceUrl(node.Id) to generate the url.
Cheers,
/Dirk
Hi Dirk,
We have tried that too ( referencing a property )
We have also tried the Umbraco.library.NiceUrl(node.id) ( I did mention that in the first post :) ) but that also returns the '#'
Hence it's a real head banger,
What I don't get, is why does re-publishing a page make things suddenly work?! Another weird thing, is that if you re-publish the site it does not fix things, if you publish the parent node it does not fix things... you have to actually publish the individual page that is not working and then ping.... it works.
Cheers,
Chris
Well, as so far no one seems to know the answer to this, I've downloaded the Umbraco 4.7.1 source...
I have modified the NiceUrl method so that instead of catching and ignoring errors, it now logs them to the umbracoLog table like so:
As you can see I also left in the default behaviour, which is to return a '#' if there is an error, so we now all know where these '#' symbols are coming from :)
The error that is being logged is:
So, as you can see the NiceUrl method calls niceUrlDo... which calls NiceUrlFetch.... which in turn calls NiceUrlJuno... which is where our error is occuring.
The first lines of this method are:
And the error is coming from the UmbracoContext.Current as it is equal to NULL !!?!
So... long story short... by adding the following to the top of the NiceUrl method:
And a similar check in the requestModule.cs - Application_Request method:
This fixes this bug :)
Can anyone see any issues with those changes as everything seems to work fine?
The reason for the issue is that the UmbracoContext does not get created until the Application_Request method fires and this is AFTER the URL Redirect module tries to do it's re-directing and hence there is no Context.
Cheers all,
Chris
is working on a reply...