HttpError iis config throws exception when default path is added
Asked Answered
S

4

13

I have this config which works and redirects the following errors correctly

<httpErrors errorMode="Custom" 
        existingResponse="Replace" 
        defaultResponseMode="ExecuteURL" >
  <remove statusCode="403" />
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/ApplicationError" />
</httpErrors>

But when I add the following default path to try to add a catch all

<httpErrors errorMode="Custom" 
        existingResponse="Replace" 
        defaultResponseMode="ExecuteURL" 
        defaultPath="/Error/ApplicationError">

The server throws a web.config error

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Module     CustomErrorModule

Now this directly contradicts the documentation on msdn

Any help would be greatly appreciated!!

Scrutineer answered 28/3, 2014 at 10:20 Comment(5)
This answer helped me serverfault.com/a/53713/243181 For IISExpress applicationHost.config can be found in another location - https://mcmap.net/q/22569/-where-is-the-iis-express-configuration-metabase-file-foundCasas
@IvanSamygin:did not fix it for me.Compendium
Has anybody solved it yet? I'm having the exact same problem. It's as if defaultPath does not work.Stigmasterol
Anyone found some fix for this?Subsequent
okay this worked (the iis config settings), I just had existingResponse="Auto" instead of existingResponse="Replace". My bad, sorry.Subsequent
T
7

You cannot override httpErrors "defaultPath" attribute in IISExpress because of applicationhost.config locked that attribute:

<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">

You can read more about it here: https://support.microsoft.com/en-us/kb/942055 This problem can occur:

when the specified portion of the IIS configuration file is locked at a higher configuration level. To resolve this problem, unlock the specified section, or do not use it at that level. For more information on configuration locking, see How to Use Locking in IIS 7.0 Configuration.

Tantalize answered 18/8, 2016 at 19:26 Comment(2)
this actually doesn't seem to work as now instead of 500.19 web.config error, I'm getting default iis error pages instead of my customized ones. Please Help.Subsequent
okay this worked (the iis config settings), I just had existingResponse="Auto" instead of existingResponse="Replace". My bad, sorry.Subsequent
D
6

Using of defaultPath attribute prevents using of path attribute in your error nodes. So below configuration will work (but of course it will show the same error page for all HTTP errors defined here):

<httpErrors errorMode="Custom" existingResponse="Replace"
  defaultResponseMode="ExecuteURL" defaultPath="/Error/ApplicationError">
  <remove statusCode="403" />
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="403" responseMode="ExecuteURL" />
  <error statusCode="404" responseMode="ExecuteURL" />
  <error statusCode="500" responseMode="ExecuteURL" />
</httpErrors>

Related doc: https://msdn.microsoft.com/en-us/library/ms690576(v=vs.90).aspx

Destruction answered 25/4, 2015 at 10:31 Comment(3)
I'm afraid it won't work - it will show "Missing required attribute 'path'", because you did not specify the path attribute for your "error" entries. Have you tried your configuration? Did it work? I'm just wondering because on IIS7 I'm getting the error I just described.Stigmasterol
Yes, I've tried this configuration with manually modified web.config file on IIS 8.0 Express and it's worked fine at that time. (i.e. defaultPath attribute assigns path attribute for all error nodes internally). I guess you're getting this error in IIS Manager which is by some reason (maybe bug) prevents this kind of configuration...Destruction
The linked doc says: An optional string value that contains the default path of an HTTP error file or URL. When nonempty, this value is inherited by the Path property of newly created HttpErrorElement objects.Constrained
S
2

This is becuase IIS by default (Ive just discovered this with IIS 10) at a server level locks defaultPath.

The error is saying some parent web.config attribute has been locked so you're not allowed to overwrite it.

The way to change this is to

  1. Open IIS
  2. Select the top level node in the tree (Your server/computer name most likely)
  3. Click the 'Configuration Editor' icon in the last row.
  4. Enter 'system.webServer/httpErrors' into the section dropdown at the top Configuration Editor -> httpErrors -> defaultPath attribute
  5. Right click the defaultPath
  6. Go to the 'defaultPath' attribute > sub menu
  7. Click Unlock attribute
  8. Click Apply Changes in the top right

I'd generally recommend against this though, as you'll have to do this on every server you deploy the site to. (and I'm also not sure how something like Azure Web apps that dont give you this level of access handle it)

Shenitashenk answered 16/9, 2020 at 5:22 Comment(0)
R
-2

Try defaultPath="~/Error/ApplicationError" with ~.

Rigadoon answered 28/3, 2014 at 10:38 Comment(1)
did not fix it for me.Compendium

© 2022 - 2024 — McMap. All rights reserved.