Introduction
During the development of SKUM3 some problems have not manifested themselves while developing for one simple reason: Visual Studio 2008 uses a version of IIS 6 as a development server, but our final setup will be an IIS 7 server. The differences between these two version are significant enough to cause headaches.
One such headache is the inability to debug code running on the remote server. This combined with differences in how errors are handled, both in the setup in the web.config file, and in the way a custom error handler is called, produced a very difficult to solve problem. Also a lack in documentation is partly to blame.
The problem
web.config differences.
IIS 7 version:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath=""
path="/path/to/handlerwebservice"
responseMode="ExecuteURL" />
</httpErrors>
IIS 6 version:
<customErrors mode="On"> <error statusCode="404" redirect="webservices/media/image"/> </customErrors>
With the IIS 6 version all 404 errors are redirected to webservices/media/image?aspxerrorpath=original/path. In IIS 7 though this querystring parameter is missing so what to do?
The Solution
Well, microsoft is not very helpful and I tried asking my question to the Internet but as I didn’t receive any answers I just tried changing
context.Request.Path
to
context.Request.RawUrl
Resulting in this code to handle the differences:
string requestpath;
if(context.Request.QueryString.AllKeys.Contains("aspxerrorpath"))
{
requestpath = context.Request.QueryString["aspxerrorpath"];
}
else
{
requestpath = context.Request.RawUrl;
}
This seemed to have the desired effect. The difference between these two are that RawUrl contains the requested path unaltered by redirection or anything else and Path is the Url after any redirection. I had forgotten this minor detail even though I’ve used it in the breadcrumb method to split an original path up into individual pieces, after the request had been redirected by our UrlRewriter.
If you are getting weird errors about httpErrors being locked down use a cheat code
%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/httpErrors
Tags: .NET, c#, httpErrors, httpHandler, IHttpHandler, iis 7.0, iis7
Thank you for your info,I hope itt will help me a lot…
I am just trying to get our site to move to iis7 (without success until now)
We use our custom module and our site has different handlers(separate DDL-s) for Auth,CSS,Nicename and I ccan’t get them working.
Do u think we will need to change also the code ?
I am right night a bit confused as there so many information in google so may be just need to clear out the things.
Would help me a lost if I would have a config.files examples may be would share it if I ask you ?( (and I mean not just the web.config, …system32\inetsrv\applicationHost.config,redirection.config, machine.config, and if there anything elsewhere other config :-)