IIS7 - combination of ASP.NET customErrors, IIS httpErrors - asp.net

I've seen a number of similar questions to this on StackOverflow and on other sites, but nothing that seems to resolve the issue I'm experiencing.
I'm trying to configure a site to return a 500 status code and a custom error page (static HTML file) for ASP.NET errors that would normally return a 500 where customErrors is set to "Off", and 404 status code for pages that our system reports as not being found (the 404 page is not a static page set via IIS, it's generated by our CMS system).
I'm part way there, but I've hit a bit of a brick wall.
At present, I'm able to return the correct 404 status code where our system returns a page with a 404 status code, but I'm now unable to return a 500 status code for ASP.NET server errors. I managed this by setting Response.TrySkipIisCustomErrors = true. My 500 errors, however, are proving more complicated. If I remove the customErrors config section from my web.config, I get the 500 error but it's the ugly ASP.NET YSOD. I can't seem to get this to point to a custom page using IIS at all, no matter what settings I use for the httpErrors config section and no matter what I set via the IIS GUI. If I add the customErrors section back, I get the custom error page as I'd expect, but I get a 200 or 302 error (depending on the value of redirectMode attribute).
Anyone got any ideas?
In terms of httpErrors config section I've tried the following so far:
Setting errorMode to "Custom" and specifying my static content for errors with a statusCode of "500" and a subStatusCode of "-1" (removing existing 500 error first)
Setting errorMode to "Detailed" and specifying my static content for errors with a statusCode of "500" and a subStatusCode of "-1" (removing existing 500 error first)
Setting existingResponse="PassThrough" for both configuration options above.

It seems you may be going above and beyond what you need to do, that is if I understand you correctly. Here is a good link
It seems like you what you need is to handle the global.asax Application_Error Event. This way you can handle it anyway you like and you dont get that ugly asp.net error screen. Any web app I create I put some code in there to handle errors so the user wont see any unformatted "blow ups"

Related

can't get custom 404 redirect to work IIS7

We have a couple of hundred web sites that each have their own web.config file and so far the only suggestion I've found for this issue is to update the web.config file (for example - IIS7 custom 404 not showing). That isn't going to happen with these many sites. I'm hoping there's an alternative.
I have the following method called when some information can't be loaded on a page. When I run it locally it does redirect me to 404Err.aspx but it doesn't when running on the live site (IIS7).
private void Set404()
{
Response.Clear();
Response.Status = "404 Not Found";
Response.StatusCode = 404;
Server.Transfer("~/404Err.aspx");
}
I started to wonder if by setting the statuscode to 404, it triggers the 404 error within IIS. So I tried editing the 404 Error Pages on the server by going to IIS>Error Pages>404>Edit Feature Set, select Custom error pages, provide the path /404Err.aspx and type is Execute URL. Still no luck.
I use this same method on windows 03, IIS6 boxes and it works fine. Is there anything else I can do besides editing the web.config file?

Response.TrySkipIisCustomErrors not working

I have a page where i want the page to return a 404 response but remain on that page. Please don't ask why - the client wants it that way even after i discussed it with him.
I've got a .net page written in C# running under iis 8 and the app pool is configured to run under 4.0 integrated mode
When i set the statuscode to 404 in the page, it gets sent to the custom 404 error page that's set up for this site. After googling i found another post on SO mention using Response.TrySkipIisCustomErrors. From what i read it sounds like it's exactly what i need. I tried setting it to true and it had no effect in the behavior of the page - still get sent to the customer 404 error page that's setup in iis.
Anyone have any ideas why this isn't working?
Well - this is a first. First time I managed to find the answer before hitting the submit button :)
Found this IIS.net article:
http://www.iis.net/configreference/system.webserver/httperrors
which then lead me to find this:
http://msdn.microsoft.com/en-us/library/ms690576(v=vs.90).aspx
Scroll down to the part that explains what the options for existingResponse mean. I had mine set to Replace which means it ignores TrySkipIisCustomErrors completely. Changed it to Auto and it's working.

Global.asax not firing for .aspx pages in IIS7

We run a link redirection service which can handle links thrown at it in various formats. One of these formats is to append the destination URL to the end of the link, for example
http://url.fwd/abcd/http://www.mydomain.com/page.aspx
This was working on a Windows Server 2003 / IIS6 box for the last two years, but now we're trying to move to a Windows Server 2008 / IIS7 setup and its not working anymore.
I've read about the problem with colons in the URL but it doesn't affect pages not ending in '.aspx'. For instance,
http://url.fwd/abcd/http://www.mydomain.com/page.php
would redirect fine.
http://url.fwd/abcd/http//www.mydomain.com/page.aspx
also works fine (note the lack of a second colon). Despite being the wrong URL, it does get handled by our URL forwarding system, which uses a custom 404 page. On the old system, we had a similar problem, so a method was written in Global.asax > Application_Error specifically to handle the '.aspx' case, and it worked fine.
On our new server, the Application_Error never gets thrown in Global.asax. Instead, I get a System.NotSupportedException - "The given path's format is not supported". This System.NotSupportedException is the exact case we handle in the Global.asax page, so it's definitely not being fired.
I've changed the registry keys indicated in several forum posts,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET VerificationCompatibility=1
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP|Parameters AllowRestrictedChars=1
I've tried changing the Handler Mappings settings for .aspx.
I've tried setting the App pool to use classic mode instead of integrated, but this causes a completely different error where static content such as images and CSS do not display at all. I've checked that static content is enabled in the windows features, and it is.
Under classic mode, the '.aspx' request throws two Bad Request errors with absolutely no information whatsoever. The code of the error page I get is literally
Bad Request<html><body>Bad Request</body></html>
UPDATE: I've changed the static file Handler Mapping to the form found in this page
http://improve.dk/blog/2006/12/11/making-url-rewriting-on-iis7-work-like-iis6
However, as the author rightly points out, this is a hack and not the correct way of doing things under IIS7. It also only fixes the static file problem in classic mode. '.aspx' pages still throw an error under classic mode.
Any thoughts or input would be greatly appreciated at this point.
IIS 7 Solution
The easy solution in IIS 7 is to add a setting in your web.config file to tell IIS to process all requests through your Global.asax events. Just add or change this section in your web.config to enable requests:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
In my case, I was publish my site in production and I miss copy to server App_global.asax.compiled file. For this reason was not fire the Events inside Global.asax.
Hope anyelse help this tips, I lost 8 hours seeking.

Detailed 500 error message, ASP + IIS 7.5

IIS 7.5 , 2008rc2, classic asp, 500 error msg:
The page cannot be displayed because an internal server error has occurred.
I need to know how to configure IIS to get a more detailed error.
I've tried setting to true all of debugging options in the ASP configuration.
But that didn't work. Can anyone help me?
I have come to the same problem and fixed the same way as Alex K.
So if "Send Errors To Browser" is not working set also this:
Error Pages -> 500 -> Edit Feature Settings -> "Detailed Errors"
Also note that if the content of the error page sent back is quite short and you're using IE, IE will happily ignore the useful content sent back by the server and show you its own generic error page instead. You can turn this off in IE's options, or use a different browser.
If you're on a remote server you can configure your web.config file like so:
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
Double click "ASP" in the site's Home screen in IIS admin, expand "Debugging Properties", enable "Send errors to browser", and click "Apply".
Under "Error Pages" on the home screen select "500", then "Edit feature settings" and select "Detailed Errors".
Note that the same steps apply for IIS 8.0 (Windows Server 2012).
After trying Vaclav's and Alex's answer, I still had to disable "Show friendly HTTP error messages" in IE
TLDR:First determine where in the pipeline you're getting the error from (scroll looking for screenshots of something that resembles your error), make changes to get something new, repeat.
First determine what error message you are actually seeing.
If you are seeing the file located here...
%SystemDrive%\inetpub\custerr<LANGUAGE-TAG>\500.htm
...which generally looks like this:
**...then you know you are seeing the currently configured error page in IIS ** and you do NOT need to change the ASP.net customErrors setting, asp error detail setting, or "show friendly http errors" browser setting.
You may want to look at the above referenced path instead of trusting my screenshot just in case somebody changed it.
"Yes, I see the above described error..."
In this case, you are seeing the setting of <httpErrors> or in IIS Manager it's Error Pages --> Edit Feature Settings. The default for this is errorMode=DetailedLocalOnly at the server node level (as opposed to the site level) which means that while you will see this configured error page while remote, you should be able to log on locally to the server and see the full error which should look something like this:
You should have everything that you need at that point to fix the current error.
"But I don't see the detailed error even browsing on the server"
That leaves a couple of possibilities.
The browser you are using on the server is configured to use a proxy
in its connection settings so it is not being seen as "local".
You're not actually browsing to the site you think you are browsing to - this commonly happens when there's a load balancer involved. Do a ping check to see if dns gives you an IP on the server or somewhere else.
Your site's httpErrors settings is set for "Custom" only. Change it to "DetailedLocalOnly". However, if you have a configuration error, this may not work since the site level httpErrors is also a configuration item. In that case proceed to #4
The default for httpErrors for all sites is set for "Custom". In this case you need to click on the top level server node in IIS Manager (and not a particular site) and change the httpErrors settings there to DetailedLocalOnly. If this is an internal server and you're not worried about divulging sensitive information, you could also set it to "Detailed" which will allow you to see the error from clients other than the server.
You're missing a module on the server like UrlRewrite (this one bites me a lot, and it often gives the generic message regardless of the httpErrors settings).
"Logging on to the server is not an option for me"
Change your site's httpErrors to "Detailed" so you can see it remotely. But if it doesn't work your error might already be a config error, see #3 immediately above. So you might be stuck with #4 or #5 and you're going to need somebody from your server team.
"I'm not seeing the error page described above. I'm seeing something different"
If you see this...
...and you expect to see something like this...
...then you need to change "Send errors to browser" to true in IIS Manager, under Site --> IIS --> ASP --> Debugging Properties
If you see this...
or this...
...you need to disable friendly errors in your browser or use fiddler's webview to look at the actual response vs what your browser chooses to show you.
If you see this...
...then custom errors is working but you don't have a custom error page (of course at this point were talking about .net and not classic asp). You need to change your customErrors tag in your web.config to RemoteOnly to view on the server, or Off to view remotely.
If you see something that is styled like your site, then custom errors is likely On or RemoteOnly and it's displaying the custom page (Views->Shared->Error.cshtml in MVC for example). That said, it is unlikely but possible that somebody changed the pages in IIS for httpErrors so see the first section on that.
In web.config under
<system.webServer>
replace (or add) the line
<httpErrors errorMode="Detailed"></httpErrors>
with
<httpErrors existingResponse="PassThrough" errorMode="Detailed"></httpErrors>
This is because by default IIS7 intercepts HTTP status codes such as 4xx and 5xx generated by applications further up the pipeline.
Next, enable "Send Errors to Browser" under the "ASP" section, and under "Error Pages / Edit Feature Settings", select "Detailed errors".
Also, give Write permissions on the website folder to the IIS_IUSRS builtin group.
try setting the value of the "existingResponse" httpErrors attribute to "PassThrough". Mine was set at "Replace" which was causing the YSOD not to display.
<httpErrors errorMode="Detailed" existingResponse="PassThrough">
One thing nobody's mentioned is as a very quick and temporary fix, you can view the error on the localhost of that web server.
You may also verify that if you changed your main website folder (c:\inetpub\wwwroot) to another folder you must give read permission to the IIS_IUSRS group in the new folder.
Fot people who have tried EVERYTHING and just CANNOT get the error details to show, like me, it's a good idea to check the different levels of configuration. I have a config file on Website level and on Application level (inside the website) check both. Also, as it turned out, I had Detailed Errors disabled on the highest node in IIS (just underneath Start Page, it has the name that is the same as the webservers computername). Check the Error Pages there.
Found it.
http://blogs.iis.net/ksingla/archive/2009/02/16/iis-7-5-updates-to-custom-errors-and-compression.aspx
run cmd as administrator, go to your system32\inetsrv folder and execute:
appcmd.exe set config -section:system.webServer/httpErrors -allowAbsolutePathsWhenDelegated:true
Now I can see detailed asp errors .
If you run the browser in the server and test your url of the project with the local ip you have received all errors of that project without a generally error page(for example 500 error page).
In my case it was permission issue.
Open application folder properties -> Security tab -> Edit -> Add
IIS AppPool\[DefaultAppPool or any other apppool] (if use ApplicationPoolIdentity option)
IUSRS
IIS_IUSRS
Double check the encoding of the asp file you are testing.
For instance if you created a file like below on a Windows Server Core 2019 :
echo "<%# LANGUAGE=Javascript %>" > test.asp
echo "<%Response.Write("test");%>" >> test.asp
Then test.asp will be encoded in Unicode, and requesting it will produce a 500 without any details.
Do a notepad test.asp, then click on "Save As..." and choose "ANSI" encoding to fix it.

Classic ASP always return code 200 in IIS7

I enabled tracing in IIS7.
I set those properties to true in the ASP tab of the IIS management tool:
appAllowClientDebug,
appAllowDebugging,
errorsToNTLog,
scriptErrorSentToBrowser;
To test it, I wrote a small classic ASP test page in wich I voluntary include a bug (bad activeX name).
My asp test page is rendered until the bug line is reached. The rest of the page is not rendered. I was expecting a 500 error code, but code is always 200. There is no error file in the FailedReqLogFiles folder.
Any idea someone?
OK, i think the issue is actually with Enable Server Side Debugging. You may have it enabled, but you should disable it instead.
The server thinks it should start debugging and tries to fire up a debugger, and then doesn't find one and just gives up! I'm sure this never happened prior to IIS7.
Glood Morning,
This problem was slowing our development significantly, because sql server errors were not displayed on the browser. Our Application Service Provider tried some settings, but couldn't get it to work. They sent me the settings and I accidentally did just two at once and our problem was fixed. They told me that asp was giving return code 200 instead of the error code.
Here is what worked for us:
The combination of "Send to Browser = True" and "Enable Server Side Debugging" = False" works.
I hope that helps others.
Tom Armstrong
Look at this and see if this is stopping you from getting the 500 error. Also, If the bug is handled through an exception handler in the activeX then you might not be seeing an error on the asp response.
http://classicasp.aspfaq.com/general/why-do-i-get-a-500-internal-server-error-for-all-asp-errors.html
200 OK is a Standard response for successful HTTP requests. The status code indicates that the client's request was successfully received, understood, and accepted.
We had this same IIS7 error happening. It was not returning any kind of error. There was no error message on the screen and no 500. The page just stopped rendering.
Is that what you are seeing? I can't remember what it was unfortunately, i think it was like something was handling the error. (If this is what you are seeing, i will keep trying to remember!)
I don't think this is it but it might be: go into Error Pages > Edit Feature Settings (hidden on the right panel) and select Detailed Error? That setting is also required and you didn't mention it.

Resources