Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Sitecore throw a NullReferenceException exception when I redirect to one of its pages?

I'm running Sitecore 6.1 on Windows 2008, IIS7, and I'm trying to use the URL Rewrite Module to do a redirect. When I enable the rule and hit the URL that triggers it, I get a YSOD. The same rule works perfectly on a non-sitecore site on the same machine. According to the Failed Request Trace, the rewrite module does its thing just fine, but then Sitecore throws an exception, even if the redirect points to another server. This is probably a result of something I have misconfigured, but I just can't understand why it doesn't work. The details from the YSOD are below.

[NullReferenceException: Object reference not set to an instance of an object.]  
   Sitecore.Nexus.Web.HttpModule.(Object sender, EventArgs e) +273  
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68  
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75  
like image 928
Abs Avatar asked Feb 28 '10 15:02

Abs


4 Answers

Sitecore has it's own engine for URL redirection, so some wires are probably getting crossed here. Possibly you need to move your HttpModule so it's executing earlier in the chain.

like image 71
Bryan Avatar answered Nov 14 '22 22:11

Bryan


Sitecore claim to have fixed this in release 6.2 rev.100831 (Update-4) - http://sdn.sitecore.net/Products/Sitecore%20V5/Sitecore%20CMS%206/ReleaseNotes/KnownIssues%20Recommended/Rewriting%20URLs.aspx

like image 39
Julian Avatar answered Nov 14 '22 23:11

Julian


Use the pipeline mode "Classic" rather than "Integrated"

http://sdn.sitecore.net/Products/Sitecore%20V5/Sitecore%20CMS%206/ReleaseNotes/KnownIssues%20Recommended/Rewriting%20URLs.aspx

like image 1
Dan Avatar answered Nov 14 '22 22:11

Dan


You can get the same error when doing

Response.Redirect("~/SomeUrl.aspx")

within C# code, the way to fix this is to use the overloaded:

Response.Redirect("~/SomeUrl.aspx", true)

which will end the response immediately.

The rewrite module is obviously not ending the request immediately allowing Sitecore to hit this problem. You could get around this problem by creating a module to deal with the redirects or trying to extend the URL Rewrite Module to end the response immediately.

like image 1
Rhys Godfrey Avatar answered Nov 14 '22 21:11

Rhys Godfrey