282

I get an error everytime I upload my webapp to the provider. Because of the customErrors mode, all I see is the default "Runtime error" message, instructing me to turn off customErrors to view more about the error.

Exasperated, I've set my web.config to look like this:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

And still, all I get is the stupid remote errors page with no useful info on it. What else can I do to turn customErrors OFF ?!

C. Tewalt
  • 2,271
  • 2
  • 30
  • 49
Radu094
  • 28,068
  • 16
  • 63
  • 80
  • 1
    try add `@Model.Exception.Message` to the `Shared/Error.cshtml` – Muflix Feb 09 '17 at 14:42
  • In general, watch out for config transforms (e.g. Web.Debug.config which could change that value), and watch out for duplicate definitions of that section/property in the file (clearly wasn't the issue in this case) – Graham Feb 16 '18 at 10:16

31 Answers31

181

This has been driving me insane for the past few days and couldn't get around it but have finally figured it out:

In my machine.config file I had an entry under <system.web>:

<deployment retail="true" />

This seems to override any other customError settings that you have specified in a web.config file, so setting the above entry to:

<deployment retail="false" />

now means that I can once again see the detailed error messages that I need to.

The machine.config is located at

32-bit

%windir%\Microsoft.NET\Framework\[version]\config\machine.config

64-bit

%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
starball
  • 20,030
  • 7
  • 43
  • 238
  • Good point. It's best to turn retail mode back to true when you've finished however (or turn off debug mode in web.config, which will be annoyance on your development machine). See http://weblogs.asp.net/lasse/archive/2009/04/28/the-asp-net-lt-deployment-retail-true-gt-attribute.aspx – Stephen Kennedy Feb 28 '12 at 12:42
  • This seems to be a default setting in .NET 4.0 - I had the same trouble figuring it out. Agree that it's a good setting to use in a production environment, but seeing the REAL error is very important when debugging. – Jeremy Dec 19 '12 at 14:48
  • Is there security problem if this set to false forever? – Majid Basirati Dec 14 '20 at 07:24
153

"Off" is case-sensitive.

Check if the "O" is in uppercase in your web.config file, I've suffered that a few times (as simple as it sounds)

juan
  • 80,295
  • 52
  • 162
  • 195
56

In the interests of adding more situations to this question (because this is where I looked because I was having the exact same problem), here's my answer:

In my case, I cut/pasted the text from the generic error saying in effect if you want to see what's wrong, put

<system.web>
   <customErrors mode="Off"/>
</system.web>

So this should have fixed it, but of course not! My problem was that there was a <system.web> node several lines above (before a compilation and authentication node), and a closing tag </system.web> a few lines below that. Once I corrected this, OK, problem solved. What I should have done is copy/pasted only this line:

<customErrors mode="Off"/>

This is from the annals of Stupid Things I Keep Doing Over and Over Again, in the chapter entitled "Copy and Paste Your Way to Destruction".

Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121
  • Question: This answer implies that ASP reads web.config and other config files from the top, ie: top-down. I thought config files were read as a "single instance" meaning that the compiler first parses the config file for accuracy and then compiles it, but it seems to be compiling it on the fly - line by line. Is that true? – Fandango68 May 27 '15 at 00:03
  • @Fernando68, this might better be put in as a separate question -- a discussion in comments isn't exactly optimal. I am not a .NET engineer, but clearly .NET is not compiling it line by line. It's an Xml file, and is therefore hierarchical. But if the hierarchy is poorly formed, the Xml parser will thrown an exception while parsing it. In other words, it has to take the entire Xml file as a whole -- but if it encounters bad Xml it can't build the required object at all! – Cyberherbalist May 27 '15 at 21:17
  • I already have raised it as a separate question http://stackoverflow.com/questions/30471043/how-does-asp-net-compile-config-files-such-as-web-config-or-machine-config . Thanks for your response, which is effectively the answers I got in my other post. Cheers – Fandango68 May 28 '15 at 00:12
10

For Sharepoint 2010 applications, you should also edit C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config and define <customErrors mode="Off" />

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
7

You can generally find more information regarding the error in the Event Viewer, if you have access to it. Your provider may also have prevented custom errors from being displayed at all, by either overriding it in their machine.config, or setting the retail attribute to true (http://msdn.microsoft.com/en-us/library/ms228298(VS.80).aspx).

John Saunders
  • 160,644
  • 26
  • 247
  • 397
7

The one answer that actually worked to fix this I found here: https://stackoverflow.com/a/18938991/550975

Just add this to your web.config:

<configuration>  
  <system.webServer>  
    <httpErrors existingResponse="PassThrough"/>  
  </system.webServer>  
<configuration>
Community
  • 1
  • 1
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
7

I tried most of the stuff described here. I was using VWD and the default web.config file contained:

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>

I changed mode="RemoteOnly" to mode="Off". Still no joy. I then used IIS manager, properties, ASP.Net Tab, Edit configuration, then chose the CustomeErrors tab. This still showed RemoteOnly. I changed this to Off and finally I could see the detailed error messages.

When I inspected the web.config I saw that there were two CustomErrors nodes in the system.web; and I have just noticed that the second entry (the one I was changing was inside a comment). So try not to use notepad to inspect web.config on a remote server.

However, if you use the IIS edit configuration stuff it will complain about errors in the web.config. Then you can rule out all of the answers that say "is there an XML syntax error in your web.config"

Khanzor
  • 4,830
  • 3
  • 25
  • 41
  • Changing the web.config on the Web Site level worked for me. Previously I had tinkered with the application's web.config file loads, failing. Thanks! – The1nk Jun 18 '13 at 15:35
6

My problem was that i had this defined in my web.config

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/Internal" />
</httpErrors>
Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
Dongolo Jeno
  • 414
  • 6
  • 8
5

If you're still getting that page, it's likely that it's blowing up before getting past the Web.Config

Make sure that ASP.Net has permissions it needs to things like the .Net Framework folders, the IIS Metabase, etc. Do you have any way of checking that ASP.Net is installed correctly and associated in IIS correctly?

Edit: After Greg's comment it occured to me I assumed that what you posted was your entire very minimal web.config, is there more to it? If so can you post the entire web.config?

Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • The few times I've run into this problem, it turned out to be an error in the web.config - definitely go over it w/ a fine-toothed comb first. – Greg Hurlman Sep 19 '08 at 13:14
  • Yes, exasperated I've overriden my web.config to this minimal settings. Still no joy – Radu094 Sep 19 '08 at 14:48
  • The user on the application pool being used did not have read permissions to the directory my app was deployed to. Still can't figure out why I could not get an error to show that let me know that was the problem. – lambacck Aug 02 '09 at 23:37
  • Often this error can be found only in the system/security event log (until IIS 7), but having access to the event log easily in most cases is the trouble. – Nick Craver Aug 03 '09 at 12:50
5

I also had this problem, but when using Apache and mod_mono. For anyone else in that situation, you need to restart Apache after changing web.config to force the new version to be read.

Michael Low
  • 24,276
  • 16
  • 82
  • 119
2

I had the same issue but found resolve in a different way.

-

What I did was, I opened Advanced Settings for the Application Pool in IIS Manager.

There I set Enable 32-Bit Applications to True.

Levi
  • 661
  • 7
  • 26
2

Actually, what I figured out while hosting my web app is the the code you developed on your local Machine is of higher version than the hosting company offers you. If you have admin privileges you may be able to change the Microsoft ASP.NET version support under web hosting setting

2

We had this issue and it was due to the IIS user not having access to the machine config on the web server.

Tjaart
  • 3,912
  • 2
  • 37
  • 61
2

We also ran into this error and in our case it was because the application pool user did not have permissions to the web.config file anymore. The reason it lost its permissions (everything was fine before) was because we had a backup of the site in a rar file and I dragged a backup version of the web.config from the rar into the site. This seems to have removed all permissions to the web.config file except for me, the logged on user.

It took us a while to figure this out because I repeatedly checked permissions on the folder level, but never on the file level.

Ghlouw
  • 1,440
  • 16
  • 19
1

Try restarting the application (creating an app_offline.htm than deleting it will do) and if you still get the same error message, make sure you've only declared customErrors once in the web.config, or anything like that. Errors in the web.config can have some weird impact on the application.

Adam Vigh
  • 1,260
  • 2
  • 13
  • 20
1

Do you have any special character like æøå in your web.config? If so make sure that the encoding is set to utf-8.

Frederik Vig
  • 430
  • 1
  • 4
  • 11
1

Is this web app set below any other apps in a website's directory tree? Check any parent web.config files for other settings, if any. Also, make your your directory is set as an application directory in IIS.

Greg Hurlman
  • 17,666
  • 6
  • 54
  • 86
1

If you're using the MVC preview 4, you could be experiencing this because you're using the HandleErrorAttribute. The behavior changed in 5 so that it doesn't handle exceptions if you turn off custom errors.

1

Also make sure you're editing web.config and not website.config, as I was doing.

Eleanor Zimmermann
  • 414
  • 1
  • 8
  • 26
1

You can also try bringing up the website in a browser on the server machine. I don't do a lot of ASP.NET development, but I remember the custom errors thing has a setting for only displaying full error text on the server, as a security measure.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
1

I have just dealt with similar issue. In my case the default site asp.net version was 1.1 while i was trying to start up a 2.0 web app. The error was pretty trivial, but it was not immediately clear why the custom errors would not go away, and runtime never wrote to event log. Obvious fix was to match the version in Asp.Net tab of IIS.

Roman
  • 1,177
  • 1
  • 17
  • 25
  • we had same issue. "connectionstrings" node was causing error under framework 1.1, whereas app should have been 2.0 – mosheb Feb 06 '12 at 17:36
0

Make sure you add right after the system.web

I put it toward the end of the node and didn't work.

Nayef
  • 364
  • 2
  • 8
  • 22
0

If you are doing a config transform, you may also need to remove the following line from the relevant web.config file.

<compilation xdt:Transform="RemoveAttributes(debug)" />
Rich Hildebrand
  • 1,607
  • 17
  • 15
0

Having tried all the answers here, it turned out that my Application_Error method had this:

Server.ClearError();
Response.Redirect("/Home/Error");

Removing these lines and setting fixed the problem. (The client still got redirected to the error page with customErrors="On").

EM0
  • 5,369
  • 7
  • 51
  • 85
0

I have had the same problem, and I went through the Event viewer application log where it clearly mention due to which exception this is happened. In my case exception was as below...

Exception information :

Exception type: HttpException 
Exception message: The target principal name is incorrect.  Cannot generate SSPI context.
at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

The target principal name is incorrect.  Cannot generate SSPI context.

I have just updated my password in application pool and it works for me.

toonice
  • 2,211
  • 1
  • 13
  • 20
Niraj Trivedi
  • 2,370
  • 22
  • 24
0

It's also possible in some cases that web.config is not formatted correctly. In that case you have to go through it line by line before will work. Often, rewrite rules are the culprit here.

0

That's really strange. I got this error and after rebooting of my server it disappeared.

Ustin
  • 568
  • 6
  • 19
0

For me it was an error higher up in the web.config above the system.web.

the file blah didn't exist so it was throwing an error at that point. Because it hadn't yet got to the System.Web section yet it was using the server default setting for CUstomErrors (On)

  • (This post does not seem to provide a [quality answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer and improve it, or just post it as a comment to the question.) – sɐunıɔןɐqɐp Sep 28 '18 at 06:47
0

None of those above solutions work for me. my case is

i have this in my web.config

<log4net debug="true">

either remove all those or go and read errors logs in your application folder\logs eg.. C:\Users\YourName\source\repos\YourProjectFolder\logs

kaung htet naing
  • 101
  • 1
  • 1
  • 7
0

I have had the same problem, and the cause was that IIS was running ASP.NET 1.1, and the site required .NET 2.0.

The error message did nothing but throw me off track for several hours.

SimonHL
  • 175
  • 5
  • 14
-2

It may not be IIS!

I went through all of the answers on this page, as well as several more. None of them solved our issue, BUT they are good things to check and WILL cause problems. SO check those first. If you're still pulling your hair out, and you're using PHP, check your PHP settings.

What fixed it for me was to edit our php.ini file and specify:

display_errors: On

I also set:

display_startup_errors: On

just for good measure.

That fixed the problem, and our real issue turned out to be a missed comma that was missed during dev to stage migration.

I realize this page was linked to asp.net, which we were ALSO using, and this is not an asp.net issue, but when you search for these errors, this page comes up and has some good info for fixing most common problems; just not our specific issue. The config changes did fix it, and then we could concentrate on our asp.net files!

E_net4
  • 27,810
  • 13
  • 101
  • 139
J. Gwinner
  • 931
  • 10
  • 15
  • I realize there's a tag for IIS on this question, but we had the exact same error, so you'll come to this page even if you aren't using asp.net. Thus, this is still an answer for the question - just not an answer for the question's tags. – J. Gwinner Dec 22 '22 at 00:36