NullReferenceException in RewritePath

If you are getting a NullReferenceException from RewritePath at ~/, or if image references break when your URLs end in /, you need hotfix 911300 or a subsequent update such as MS06-056.

I debugged this problem with MaxmimumASP about a year ago. Apparently, this patch comes with Visual Studio SP1, but wasn't released for the rest of the world (read: production servers) until several months later. Some hosts may still be missing the patch, so watch out.

Object reference not set to an instance of an object.

at System.Web.HttpContext.RewritePath(VirtualPath filePath, VirtualPath pathInfo, String queryString, 
    Boolean setClientFilePath)
at System.Web.HttpContext.RewritePath(String filePath, String pathInfo, String queryString, Boolean 
setClientFilePath)
at UrlRewritingNet.Web.UrlRewriteModule.OnPagePreInit(Object sender, EventArgs e)
at System.Web.UI.Page.OnPreInit(EventArgs e)
at fbs.PageBase.OnPreInit(EventArgs e) in c:\Websites\yf\app_code\BaseClasses\PageBase.cs:line 109
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean 
    includeStagesAfterAsyncPoint)

This happened when trying to rewrite http://domain.org/ to page http://domain.org/default.aspx. It's a pretty common scenario. Now, while subfolders such as http://domain.org/blog/ didn't throw an error, ASP.NET translated all of the image and hyperlink references incorrectly. But URLs ending in a non-slash character behaved fine.

There's a bit more information on the issue on Microsoft Connect, although I don't mention the subfolder issue.

Bottom line: If you see different behavior between dev and production, ask your hosting provider to update the ASP.NET runtime. I know mine (and others) test .NET patches for quite a while before installing them, since they often cause as many problems as they fix. Don't believe them if they say it's up-to-date. Get the *full* version number on System.Web.dll and compare it to yours.

Related Microsoft Connect issues

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=276542 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105061 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105149 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103229 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104436 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104429

Published on

About Nathanael

Nathanael Jones is a software engineer, father, consultant, and computer linguist with unreasonably high expectations of inanimate objects. He refines .NET, ruby, and javascript libraries full-time at Imazen, but can often be found on stack overflow or participating in W3C community groups.

ImageResizer

If you develop websites, and those websites have images, ImageResizer can make your life much eaiser. Find out more at imageresizing.net.

Imazen

I run Imazen, a tiny software company that specializes in web-based image processing and other difficult engineering problems. I spend most of my time writing image-processing code in C#, web apps in Ruby, and documentation in Markdown. Check out some of my current projects.

More articles