<error>子節點
在<customErrors>節點下還包含有<error>子節點,這個節點主要是根據服務器的HTTP錯誤狀態代碼而重定向到我們自定義的錯誤頁面,注意要使<error>子節點下的配置生效,必須將<customErrors>節點節點的Mode屬性設置為“On”。下面是一個例子:
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="403.htm" />
<error statusCode="404" redirect="404.htm" />
</customErrors>
在上面的配置中如果用戶訪問的頁面不存在就會跳轉到404.htm頁面,如果用戶沒有權限訪問請求的頁面則會跳轉到403.htm頁面,403.htm和404.htm頁面都是我們自己添加的頁面,我們可以在頁面中給出友好的錯誤提示。
<httpHandlers>節點
<httpHandlers>節點用於根據用戶請求的URL和HTTP謂詞將用戶的請求交給相應的處理程序。可以在配置級別的任何層次配置此節點,也就是說可以針對某個特定目錄下指定的特殊文件進行特殊處理。
下面是與machine.config文件同一目錄下的web.config文件中的<httpHandlers>節點配置:
<httpHandlers>
<add path="*.rules" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.xoml" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
<add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="true"/>
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true"/>
<add path="*.axd" verb="*" type="System.Web.HttpNotFoundHandler" validate="true"/>
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
<add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="true"/>
<add path="*.asmx" verb="*" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
<add path="*.rem" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
<add path="*.soap" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
<add path="*.asax" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.ascx" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.master" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.skin" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.browser" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.sitemap" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.dll.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="true"/>
<add path="*.exe.config" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="true"/>
<add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.csproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.vb" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.vbproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.webinfo" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.licx" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.resx" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.resources" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.mdb" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.vjsproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.java" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.jsl" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.ldb" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.ad" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.dd" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.ldd" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.sd" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.cd" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.adprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.lddprototype" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.sdm" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.sdmDocument" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.exclude" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.refresh" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/>
<add path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
<add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="true"/>
<add path="*" verb="*" type="System.Web.HttpMethodNotAllowedHandler" validate="true"/>
</httpHandlers>