【问题标题】:Setting a custom 404 error page programmatically以编程方式设置自定义 404 错误页面
【发布时间】:2010-10-21 03:31:42
【问题描述】:

在常规 ASP.NET 应用程序中,您可能有一个 customErrors 部分,如下所示:

<customErrors mode="On">
  <error statusCode="404" redirect="Nice-FileNotFound-Page.aspx"/>
</customErrors> 

是否可以在 Application_Start 以编程方式设置 404 错误?类似于以下内容:

// Figure out which page should be used... using some logic somewhere in the application
// (obviously) Pseudo-code: Application.ErrorCode.404.Page = Page-Found-Above

【问题讨论】:

    标签: asp.net configuration error-handling web-config


    【解决方案1】:

    您可以将该逻辑放入 Nice-FileNotFound-Page.aspx 并使用您需要的任何业务逻辑从那里重定向到适当的页面。

    【讨论】:

      【解决方案2】:

      这不是特定于asp的,但只要“Nice-FileNotFound-Page.aspx”是一个动态脚本,你就不能让它成为你想要的任何东西吗?也就是说,让它以编程方式根据逻辑计算出它应该是什么样的页面,然后是那个页面?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-25
        • 2013-09-16
        • 1970-01-01
        • 2015-03-18
        • 2011-09-07
        • 2011-07-25
        相关资源
        最近更新 更多