“路径中的非法字符”的自定义错误页面

时间:2014-03-10 14:35:12

标签: asp.net iis-6 asp.net-1.1

当引发“路径中的非法字符”错误时,我在web.config中设置的自定义错误页面不会显示。它确实适用于其他服务器错误,所以我不确定我能做什么吗?

正确显示自定义错误页面的示例请求:website.com/3f.jsp

示例请求不:website.com/%3f.jsp

Web.config:<customErrors mode="On" defaultRedirect="ErrorDisplay.aspx"></customErrors>

Stacktrace(customErrors Off)

[ArgumentException: Illegal characters in path.]
   System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str) +276
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +88
   System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) +43
   System.IO.Path.GetFullPath(String path) +82
   System.Web.HttpApplication.CheckSuspiciousPhysicalPath(String physicalPath) +19
   System.Web.Configuration.HttpConfigurationSystem.ComposeConfig(String reqPath, IHttpMapPath configmap) +175
   System.Web.HttpContext.GetCompleteConfigRecord(String reqpath, IHttpMapPath configmap) +434
   System.Web.HttpContext.GetCompleteConfig() +49
   System.Web.HttpContext.GetConfig(String name) +195
   System.Web.CustomErrors.GetSettings(HttpContext context, Boolean canThrow) +20
   System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow) +39
   System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) +486

我尝试在Global.asax Application_Error处理程序中手动捕获错误,但永远不会被调用。当有非法字符时,Application_BeginRequest甚至不会被调用,那么IIS在哪里抛出此错误,是否有办法显示自定义页面?

根据this article我可能不走运。

1 个答案:

答案 0 :(得分:1)

当您的堆栈跟踪显示并且您在Application_BeginRequest中没有被调用时,在您的应用程序代码被调用之前,IIS的请求处理中会出现此错误 - 您的第一个问题的答案:因此,您的{{1}并且不考虑Web.config实现。

related discussion on ASP.NET forums也表明了这一点。

在我的本地IIS(7.5)服务器上,我回来了......

  

错误请求 - 无效网址

     

HTTP错误400.请求网址无效。

...代表网址Application_Error

好奇,我尝试在IIS管理器的本地服务器错误页面下为HTTP状态代码400设置静态自定义错误页面,同时配置我的本地服务器以使用自定义错误页面来处理本地和远程请求;但我从未见过为此特定错误设置的自定义错误页面。

TechNet article解释了原因:

  

您无法自定义以下HTTP错误:400,403.9,411,414,500,500.11,500.14,500.15,501,503和505.

所以我认为第二个问题的答案是,不,IIS没有为您提供显示自定义错误页面的方法。