Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
831 views
in Technique[技术] by (71.8m points)

asp.net - HttpError iis config throws exception when default path is added

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...