J
James Higgs
For a long time, our product has had a "vanity URLs" feature where nice URLs
are mapped to ASPX files in an IHttpModule implementation, using HttpContext.RewritePath().
This has worked beautifully for the past couple of years under .NET 1.1,
but when it runs under ASP.NET 2.0 it has problems. Note that this is the
case regardless of whether the assmbly is built against 1.1 or 2.0
We're getting the following exception stack trace:
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)
at Interesource.Publish.Client.Web.VanityUrlModule.HttpApplication_AuthorizeRequest(Object
sender, EventArgs ea)
In my experience it's very unusual to get a NullReferenceException thrown
from inside the framework, so this warranted extra investigation.
The overload we're calling is HttpContext.RewritePath(string filePath, string
pathInfo, string queryString) and regardless of what values are passed to
the last two arguments, we get the NullReferenceException. I can't see from
Reflector how this method could possibly throw a NullReferenceException.
We did find a workaround, which was this to change our original line of:
ctx.RewritePath(physicalResource, queryString, pathInfo));
to this:
ctx.RewritePath(string.Concat(physicalResource, queryString.Length > 0 ?
"?" : "", queryString));
so that we were using a different overload on RewritePath which, according
to Reflector, doesn't go through the same code path as the first overload
we were using. As it happens, we don't need the path info. I'm at a loss
to see how this can be the result of something I'm doing wrong.
This workaround doesn't work conistently well, so at the moment, I have this
in my code:
if(Environment.Version.Major == 1)
{
ctx.RewritePath(physicalResource, req.PathInfo, queryString);
}
else
{
string url = physicalResource;
if(queryString != null && queryString.Length > 0)
{
url += "?" + queryString;
}
ctx.RewritePath(url);
}
Is it possible for this to be a bug in the framework? Is there some config
that I'm missing? Anyone else with the same issue?
I've logged the same issue at http://forums.asp.net/1109000/ShowPost.aspx
and blogged about it at http://staff.interesource.com/james/PermaLink.aspx?guid=1bd27f40-689a-41b9-b65a-4be68284949d
Hopefully this is a more appropriate place for a response.
are mapped to ASPX files in an IHttpModule implementation, using HttpContext.RewritePath().
This has worked beautifully for the past couple of years under .NET 1.1,
but when it runs under ASP.NET 2.0 it has problems. Note that this is the
case regardless of whether the assmbly is built against 1.1 or 2.0
We're getting the following exception stack trace:
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)
at Interesource.Publish.Client.Web.VanityUrlModule.HttpApplication_AuthorizeRequest(Object
sender, EventArgs ea)
In my experience it's very unusual to get a NullReferenceException thrown
from inside the framework, so this warranted extra investigation.
The overload we're calling is HttpContext.RewritePath(string filePath, string
pathInfo, string queryString) and regardless of what values are passed to
the last two arguments, we get the NullReferenceException. I can't see from
Reflector how this method could possibly throw a NullReferenceException.
We did find a workaround, which was this to change our original line of:
ctx.RewritePath(physicalResource, queryString, pathInfo));
to this:
ctx.RewritePath(string.Concat(physicalResource, queryString.Length > 0 ?
"?" : "", queryString));
so that we were using a different overload on RewritePath which, according
to Reflector, doesn't go through the same code path as the first overload
we were using. As it happens, we don't need the path info. I'm at a loss
to see how this can be the result of something I'm doing wrong.
This workaround doesn't work conistently well, so at the moment, I have this
in my code:
if(Environment.Version.Major == 1)
{
ctx.RewritePath(physicalResource, req.PathInfo, queryString);
}
else
{
string url = physicalResource;
if(queryString != null && queryString.Length > 0)
{
url += "?" + queryString;
}
ctx.RewritePath(url);
}
Is it possible for this to be a bug in the framework? Is there some config
that I'm missing? Anyone else with the same issue?
I've logged the same issue at http://forums.asp.net/1109000/ShowPost.aspx
and blogged about it at http://staff.interesource.com/james/PermaLink.aspx?guid=1bd27f40-689a-41b9-b65a-4be68284949d
Hopefully this is a more appropriate place for a response.