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.Ht tpApplication_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/...a-4be68284949d
Hopefully this is a more appropriate place for a response. 15 6602
The System.Web.HttpContext.RewritePath method, in 2.0, is :
System.Web.HttpContext.RewritePath(VirtualPath filePath,
VirtualPath pathInfo, String queryString, Boolean setClientFilePath)
You're getting the "Object reference not set to an instance of an object"
error because you're setting 3 parameters, while the method has 4.
I think that running :
ctx.RewritePath(physicalResource, queryString, pathInfo, false));
should fix your problem.
Use :
ctx.RewritePath(physicalResource, queryString, pathInfo, true));
if you want the clientFilePath parameter to be the same as the filePath parameter.
See : http://msdn2.microsoft.com/en-us/library/ms223300.aspx
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"James Higgs" <ja********@newsgroups.nospam> wrote in message
news:28**************************@msnews.microsoft .com... 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.Ht tpApplication_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/...a-4be68284949d
Hopefully this is a more appropriate place for a response.
Hello Juan,
I don't think that's the problem. The string, string, string overload has
been around since .NET 1.0 See here: http://tinyurl.com/bcz79
In any case, Reflector tells us that RewritePath(string, string, string)
calls RewritePath(string, string, string, bool) anyway.
In that case, I'm fresh out of suggestions.
Last note :
The page you point me to : http://tinyurl.com/bcz79 , which maps to : http://msdn.microsoft.com/library/de...pathtopic2.asp
states, very clearly, that
"This namespace, class, or member is supported only in version 1.1 of the .NET Framework"
Since you are running your app in 2.0, I'd take a close look at what that means.
The link I referred you to : http://msdn2.microsoft.com/en-us/library/ms223300.aspx
states that : "This method is new in the .NET Framework version 2.0"
Also, notice that the "optional" keyword is not used for that method.
It looks like all parameters are mandatory, including Boolean.
To me, it would seem that, even though "the string, string, string overload has been
around since .NET 1.0", the method works differently in 2.0 than it does in 1.0 or 1.1.
Did you try using ctx.RewritePath(physicalResource, queryString, pathInfo, false));
?
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"James Higgs" <ja********@newsgroups.nospam> wrote in message
news:28**************************@msnews.microsoft .com... Hello Juan,
I don't think that's the problem. The string, string, string overload has been around since .NET 1.0 See here: http://tinyurl.com/bcz79 In any case, Reflector tells us that RewritePath(string, string, string) calls RewritePath(string, string, string, bool) anyway.
You're right that that overload was new in v1.1, but it is still supported
in .NET 2.0 - see here: http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx
To be absolutely clear, these calls do _not_ work:
ctx.RewritePath("/Default.aspx", "id=5", "", false);
ctx.RewritePath("/Default.aspx", "id=5", "", true);
ctx.RewritePath("/Default.aspx", "id=5", "");
ctx.RewritePath("/Default.aspx", null, null, false);
ctx.RewritePath("/Default.aspx", null, null, true);
ctx.RewritePath("/Default.aspx", null, null);
These calls do work:
ctx.RewritePath("/Default.aspx?id=5", false);
ctx.RewritePath("/Default.aspx?id=5", true);
ctx.RewritePath("/Default.aspx?id=5");
ctx.RewritePath("/Default.aspx");
ctx.RewritePath("/Default.aspx", false);
ctx.RewritePath("/Default.aspx", true);
This makes sense, because according to Reflector, the second lot of calls
are all processed in RewritePath(string, bool), whereas the other lot all
get processed in an internal method with the following signature:
internal void RewritePath(VirtualPath filePath, VirtualPath pathInfo, string
queryString, bool setClientFilePath);
This explains why one lot of overloads works and the other lot doesn't.
I should point out that this worked correctly on v1.1 and now doesn't on
v2.0 - it looks like a regression to me.
James
Bug it at the Feedback Center : http://lab.msdn.microsoft.com/productfeedback/
You'll need a Passport account to file a bug report.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"James Higgs" <ja********@newsgroups.nospam> wrote in message
news:28**************************@msnews.microsoft .com... You're right that that overload was new in v1.1, but it is still supported in .NET 2.0 - see here: http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx
To be absolutely clear, these calls do _not_ work:
ctx.RewritePath("/Default.aspx", "id=5", "", false); ctx.RewritePath("/Default.aspx", "id=5", "", true); ctx.RewritePath("/Default.aspx", "id=5", ""); ctx.RewritePath("/Default.aspx", null, null, false); ctx.RewritePath("/Default.aspx", null, null, true); ctx.RewritePath("/Default.aspx", null, null);
These calls do work:
ctx.RewritePath("/Default.aspx?id=5", false); ctx.RewritePath("/Default.aspx?id=5", true); ctx.RewritePath("/Default.aspx?id=5"); ctx.RewritePath("/Default.aspx"); ctx.RewritePath("/Default.aspx", false); ctx.RewritePath("/Default.aspx", true);
This makes sense, because according to Reflector, the second lot of calls are all processed in RewritePath(string, bool), whereas the other lot all get processed in an internal method with the following signature:
internal void RewritePath(VirtualPath filePath, VirtualPath pathInfo, string queryString, bool setClientFilePath);
This explains why one lot of overloads works and the other lot doesn't.
I should point out that this worked correctly on v1.1 and now doesn't on v2.0 - it looks like a regression to me.
James
Hi James,
Thanks for your posting, also Juan's inputs.
As for the problem you mentioned, I'd like to comment something:
1.For ASP.NET 1.1 application, it can running correctly on target machine
with .net 2.0 framework through side by side execution as long as the 1.1
framework also installed..... Nothing in 2.0 framework will impact it.
2.It problem related to 2.0 framework if we migrate and recompile the web
application through .net 2.0 framework...(e.g by using VS.NET 2005). So
this should be your case , yes?
As for the
====================
ctx.RewritePath("/Default.aspx", "id=5", "", false);
ctx.RewritePath("/Default.aspx", "id=5", "", true);
ctx.RewritePath("/Default.aspx", "id=5", "");
ctx.RewritePath("/Default.aspx", null, null, false);
ctx.RewritePath("/Default.aspx", null, null, true);
ctx.RewritePath("/Default.aspx", null, null);
========================
I've also performed some tests on them in my local environemnt (
WIN2K3/IIS6 .NET 2.0, VS.NET 2005 PRO) , seems the above method call works
correctly in my ASP.NET 2.0 application( I've tried in both IIS and file
system app...). So I'm also wondering whether this is a project or
environment specific problem. Would you also also try testing on some
other machine to see whether this is the consistency behavior?
BTW, as for the below statement:
"This namespace, class, or member is supported only in version 1.1 of the
.NET Framework"
I think it is mainly target the differecne between 1.0 and 1.1 framework
(when 1.1 was the newly released one....), so this should not make sense to
our issue....
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <28**************************@msnews.microsoft.com >
| From: James Higgs <ja********@newsgroups.nospam>
| Subject: Re: HttpContext.RewritePath in .NET 2.0
| References: <en**************@TK2MSFTNGP12.phx.gbl>
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 671.6
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Mon, 14 Nov 2005 08:07:08 -0800
| NNTP-Posting-Host: ir-fw.interesource.com 217.169.43.2
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357971
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Done, at http://lab.msdn.microsoft.com/produc...x?feedbackid=a
4ed900e-debe-4733-9c1d-2b72a6b6efd9
|
|
Steven,
Thanks for your response. It's certainly possible that this is to do with project-specific issues, although we have the same problem on two separate projects, one upgraded from a VS2003 project and one a newly created one. Incidentally, these projects were created on different machines, so I don't think it's a machine-specific issue. It may be worth noting that both machines previously had Beta 2 installed, and one of them also subsequently had the Release Candidate installed. In both cases, the unistall procedure was followed correctly and VS2005 RTM installed without issues.
I attach a zip file with a small VS2005 web project that reproduces the problem on my machine. This repros the problem on two machines. The project is a vanilla project created using VS2005 by using File > New Web Site...
A v1.1 app running on a machine with v2.0 installed works correctly (I assume because it is running on v1.1 so 2.0 doesn't come into the equation).
Please note that I've logged this at the product feedback centre ( http://lab.msdn.microsoft.com/Produc...d-2b72a6b6efd9)
James
It seems like the ZIP file was removed in the upload of my post. In any case,
you can find the ZIP faile at the product feedback centre URL.
Hi James,
I've downloaded your repro project and try testing on my local environment.
Unfortunately, seems I can not reproduce the "Null Reference..." exception
you encountered.....
Also, here is something I've adjusted on my side after first time run you
code:
=========
void app_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
app.Context.RewritePath("/Default.aspx", "id=5", "");
}
=========
1. When specify the path for our web application in asp.net server code, we
should use the "~/..." path to specify Application Root, "/..." means
start from the website (IIS) root. So I think we should change the rewrite
code to
app.Context.RewritePath("~/Default.aspx"......);
2. As for the HttpContext.RewritePath(string, string ,string) function, the
querystring should be the third parameter rather than the second, not sure
whether its a type mistake, I changed it to
app.Context.RewritePath("/Default.aspx", "", "id=5");
and still works well.
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <28**************************@msnews.microsoft.com >
| From: James Higgs <ja********@newsgroups.nospam>
| Subject: Re: HttpContext.RewritePath in .NET 2.0
| References: <28**************************@msnews.microsoft.com >
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 671.6
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Tue, 15 Nov 2005 01:27:52 -0800
| NNTP-Posting-Host: ir-fw.interesource.com 217.169.43.2
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358167
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| It seems like the ZIP file was removed in the upload of my post. In any
case,
| you can find the ZIP faile at the product feedback centre URL.
|
|
Steven,
You're right about the typo with the id=5 - I've swapped these over and place
the tilde at the start of the path and this still makes no difference.
I can also repro it on another machine that doesn't have VS2005 installed
on it, but just IIS6, .NET 1.1 and .NET 2.0
James
Thanks for your followup James,
Yes, seems really strange. What make it difficult is that I'm wondering
whether the dev or test guys can also reproduce the behavior in their
environment since it may be hard to got a reproduce enviornment...
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <28**************************@msnews.microsoft.com >
| From: James Higgs <ja********@newsgroups.nospam>
| Subject: Re: HttpContext.RewritePath in .NET 2.0
| References: <3k**************@TK2MSFTNGXA02.phx.gbl>
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 671.6
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Wed, 16 Nov 2005 06:10:48 -0800
| NNTP-Posting-Host: ir-fw.interesource.com 217.169.43.2
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358562
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| You're right about the typo with the id=5 - I've swapped these over and
place
| the tilde at the start of the path and this still makes no difference.
|
| I can also repro it on another machine that doesn't have VS2005 installed
| on it, but just IIS6, .NET 1.1 and .NET 2.0
|
| James
|
|
Steven,
If it would help I might be able to repro this on a VPC image which you could
then use to diagnose the issue. Would that be useful?
James
Hmm. I tried this on a Windows 2003 Server /.NET 1.1 /.NET 2.0 VPC image,
and I can't reproduce the issue. Nevertheless, I've got three other machines
I can repro it on.
Thanks for your followup James,
While due to the policy limitation of newsgroup , we are not allowed to
accept VPC or large code project from external source for troubleshooting.
However, since this is likely a potential issue of the framework on certain
Server environment, I'd recommend you try contacting PSS and opening a
regular CASE on this, the support engineer there will help you do thorough
throubleshooting on this. Also, if this end to be a issue of the .net
framework, it's free of charge and will help provide you hotfix according
to the problem.
Thanks for your understanding,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <28**************************@msnews.microsoft.com >
| From: James Higgs <ja********@newsgroups.nospam>
| Subject: Re: HttpContext.RewritePath in .NET 2.0
| References: <28**************************@msnews.microsoft.com >
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 671.6
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Thu, 17 Nov 2005 07:19:25 -0800
| NNTP-Posting-Host: ir-fw.interesource.com 217.169.43.2
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358923
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hmm. I tried this on a Windows 2003 Server /.NET 1.1 /.NET 2.0 VPC image,
| and I can't reproduce the issue. Nevertheless, I've got three other
machines
| I can repro it on.
|
| This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Guadala Harry |
last post by:
I'd really appreciate it if someone would give me a"plain English"
explanation of HttpContext.RewritePath(). I read the MSDN documentation, but
still don't understand it.
According to MSDN:...
|
by: Jiho Han |
last post by:
Can someone explain in layman's term, what HttpContext.RewritePath does?
SDK doc explanation is kind of scant.
Does it only affect the request processing for the duration of the
processing(meaning...
|
by: marcmiles |
last post by:
It looks like postbacks cause a problem with HttpContext.RewritePath.
I've read about the two solutions below, but the first one seems
extensive, and the scond one seems too easy. I sent an email...
|
by: asanford |
last post by:
I want to create an ASP.NET web application that receives a form POST
message, inspects the data, and reroutes the request to one of many different
servers. I wrote an IHttpModule which...
|
by: cpnet |
last post by:
I was playing around with Beta 2 of VS2005, .NET 2.0, and built an
IHttpModule do allow me to have nice URL's in my web app. It was working
great. I had a URL like:
...
|
by: Martin |
last post by:
asp.net 2.0
I have implemented the url rewriting using httpcontext.rewrite path(
newpath, setbase) which all works fine in IE, but testing with fiddler (
www.fiddlertool.com) when you test...
|
by: Steven Nagy |
last post by:
Hi all,
I have the following file:
~/cms/page.aspx
Normally, if you hit a url like http://localhost/MyApp/cms/page.aspx?PageID=32
... this would load content dynamically. No big deal, this is...
|
by: jbitz |
last post by:
Hi,
This has got me really baffled.
This has got me really baffled. When I run Dim url As String = HttpContext.Current.Request.Url.AbsolutePath.ToLower from Application_beginRequest in...
|
by: mmorrison93 |
last post by:
Thanks in advance for any help on this problem, but i have an
HttpHandler that looks at the requested url and and tranfers context
to a particular file. The problem is the transfer will only work...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |