HttpError iis config throws exception when default path is added

后端 未结 4 1873
失恋的感觉
失恋的感觉 2020-12-16 19:39

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



        
相关标签:
4条回答
  • 2020-12-16 20:20

    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.

    0 讨论(0)
  • 2020-12-16 20:37

    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

    0 讨论(0)
  • 2020-12-16 20:39

    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
    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)

    0 讨论(0)
  • 2020-12-16 20:42

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

    0 讨论(0)
提交回复
热议问题