【问题标题】:Custom error pages based on path/URL in ASP.NETASP.NET 中基于路径/URL 的自定义错误页面
【发布时间】:2015-05-08 22:34:52
【问题描述】:

我在/panel/ 目录中有一些页面,在/website/ 目录中有一些页面。我需要根据它们的路径为这些页面设置两个不同的 404 页面,因为这些目录有不同的master pages

当我在 web.config 文件中使用 customErrors 时,它会将所有页面重定向到一个 404 页面,因此对我来说没用。

我该如何处理?我可以在global.asaxmaster pages 中处理它吗?

提前感谢。

【问题讨论】:

    标签: c# asp.net web-config http-status-code-404 global-asax


    【解决方案1】:

    您可以使用要覆盖的设置在这些位置创建较小的 web.config,或者在根 web.config 上指定多个 customErrors 设置内的 location 标签。

    您无需为此更改任何代码。

    【讨论】:

      【解决方案2】:

      您想处理 Global.asax 文件中的错误:

      void Application_Error(object sender, EventArgs e)
       { Exception exc = Server.GetLastError(); 
      if (exc is HttpUnhandledException) 
      { // Pass the error on to the error page.
       Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true); } }
      

      查看此link 了解更多信息

      【讨论】:

        猜你喜欢
        • 2010-10-07
        • 2015-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-03
        • 2010-12-20
        • 2016-11-26
        相关资源
        最近更新 更多