Link tracker doesn't work when working with multiple sites

Topics: Developer Forum, User Forum
Mar 3, 2008 at 6:21 PM
Hello,

I've configured N2 in order to manage multiple websites using the same app. (http://www.codeplex.com/n2/Thread/View.aspx?ThreadId=21805). Now, the problem is that I get an error when I create/edit a page using the N2 backend:

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 
Source Error:
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
 
Stack Trace:
 
[NullReferenceException: Object reference not set to an instance of an object.]
   N2.Web.MultipleHostsUrlParser.Parse(String url) +200
   N2.Edit.LinkTracker.Tracker.FindLinkedItems(ContentItem item) +327
   N2.Edit.LinkTracker.Tracker.OnTrackingLinks(ContentItem item) +46
   N2.Edit.LinkTracker.Tracker.persister_ItemSaving(Object sender, CancellableItemEventArgs e) +47
   System.EventHandler`1.Invoke(Object sender, TEventArgs e) +0
   N2.Persistence.NH.DefaultPersister.OnSaving(CancellableItemEventArgs args) +100
   N2.Persistence.NH.DefaultPersister.Save(ContentItem unsavedItem) +96
   N2.Edit.DefaultEditManager.Save(IItemEditor itemEditor, IPrincipal user) +1273
   N2.Web.UI.WebControls.ItemEditor.Save() +108
   N2.Edit.Edit.OnSaveCommand(Object sender, CommandEventArgs e) +185
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +105
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +163
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Seems to be something related to the link tracker, which I think I don't need, is it possible to disable it?

Thanks in advance
Coordinator
Mar 3, 2008 at 11:05 PM
Edited Mar 3, 2008 at 11:09 PM
Hay there,

I compiled some replacement files for you. These files replace n2.edit.dll which was ilmerged into one dll. Just remove n2.edit.linktracker.dll and you should be good.

If you have the time I'd like to ask you a question though. I tried to reproduce the problem but couldn't (although a found another a nasty little nest of legacy code with another bug in it). What url did you link from your page for it to throw up like that?

Edit: Found it nm

Thanks
/Cristian
Mar 4, 2008 at 11:11 AM

libardo wrote:
What url did you link from your page for it to throw up like that?

Any URL. The exception is thrown when there's a url (linking anywhere) in the text.

Maybe the problem is caused by my own code. I'll keep looking at it and tell you any news.

Thank you for replying so quickly!
Mar 4, 2008 at 6:28 PM
Sorry, I've just noticed that it only happens with links to external pages and "mailto:" links.
Mar 5, 2008 at 9:30 PM
Hello again libardo,

I think I've found the bug in N2. I'm sorry but wasn't able to confirm.

File: \N2DevelopmentWeb\Edit\LinkTracker\Tracker.cs
Function: public override ContentItem Parse(string url)
Lines: 65 - 66
public override ContentItem Parse(string url)
{
	if (url.StartsWith("/"))
		return base.Parse(url);
	else
	{
		string host = GetHost(url);
		Site site = GetSite(host);
		return TryLoadingFromQueryString(url) ?? Parse(Persister.Get(site.StartPageID), GetPathAndQuery(url));
	}
}

At line 63 (Site site = GetSite(host);): GetSite() returns a null value which is saved in "site", so a NullReferenceException is thrown in the next line.

Hope it helps :/
Mar 5, 2008 at 9:31 PM
Hello again libardo,

I think I've found the bug in N2. I'm sorry but wasn't able to confirm.

File: \N2DevelopmentWeb\Edit\LinkTracker\Tracker.cs
Function: public override ContentItem Parse(string url)
Lines: 65 - 66
public override ContentItem Parse(string url)
{
	if (url.StartsWith("/"))
		return base.Parse(url);
	else
	{
		string host = GetHost(url);
		Site site = GetSite(host);
		return TryLoadingFromQueryString(url) ?? Parse(Persister.Get(site.StartPageID), GetPathAndQuery(url));
	}
}
At line 63 (Site site = GetSite(host);): GetSite() returns a null value which is saved in "site", so a NullReferenceException is thrown in the next line.

Hope it helps :/
Coordinator
Mar 5, 2008 at 9:53 PM
Thanks a bunch, a fix for this is checked in.
Mar 10, 2008 at 10:05 PM
Hello again libardo,

Thanks for the non-ilmerged libraries you've uploaded.
Unfortunatelly, I need to use N2 1.3.2 (I've found another different trouble in 1.3.3 :S). Could you upload replacement files for N2 1.3.2?

BTW.: The new trouble found on 1.3.3 is that, in the backend, the links for creating/editing a part are wrong, the link for creating a new item is: /edit/new.aspx?selected={CurrentItem.TemplateUrl}?page={CurrentItem.ID}&zoneName=zone name, i think it should be: http://isaacs.om.visrez.com/edit/new.aspx?selected={CurrentItem.Path}&zoneName=zone name.
Coordinator
Mar 10, 2008 at 11:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Mar 10, 2008 at 11:45 PM
Hi. Good find. I've updated the "n2 compiled runtime" with a fix.
Mar 11, 2008 at 6:42 PM
Hello libardo,
I'm amazed, you fixed both 2 issues really quickly! Thanks a million.

Thanks for the compiled runtime you've uploaded.
Mar 12, 2008 at 1:51 PM
Hi,

is the 1.3.3 runtime updated or am I missing something...
I get the same problem running the lastest 1.3.3 with a multi-language site (using the default laungaugeswitcher.
Coordinator
Mar 12, 2008 at 4:18 PM
Yes, I updated "Compiled Runtime (upgrade/do it yourself)".

Are getting an exception from the "linktracker" when saving external links/emails?

Or is it the create item from the "zones" sidebar when editing a page problem?
Mar 12, 2008 at 5:21 PM
I am getting the exception from the linktracker, the same as the first post of this thread.
Mar 12, 2008 at 5:42 PM
Use the runtime in this page: http://www.codeplex.com/n2/Release/ProjectReleases.aspx?ReleaseId=11245
the file you need is the first one: Compiled Runtime (upgrade/do it yourself).

You should be good when using that runtime (it worked for me), reply again otherwise.
Coordinator
Mar 12, 2008 at 5:47 PM
Same here. You could also check the assembly version of n2.edit.dll. Mine is 1.0.303.1399.
Mar 13, 2008 at 8:38 AM
downloaded it again to make sure, but yes, I am using that version and the assembly version is the same.
But...
I deletede the links and saved the page; save okay
I reinstated the first link (<a href="http://www.cpv.co.uk/" target="_blank">); save okay (surprise)
I reinstated the second link (<a href="http://www.giordano.fr/www/FR/frame.php?page=produitpisol" target="blank">); save FAILED
I changed the second link to <a href="http://www.giordano.fr/www/FR/frame.php" target="_blank">; save okay

Some problem with a parameter??
I now found out the website my customer want's to link to is actually not available, but that did not seem to be the problem.
Coordinator
Mar 13, 2008 at 9:04 AM
Aha, yes. it's the page querystring since the same parameter is used internally. Thanks for finding this.
Coordinator
Mar 13, 2008 at 8:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.