404 页面适用于本地主机,但不适用于生产(Azure Web App)

2024-03-28

我的本地主机上有一个 404 页面,运行得很好。但是,当它被推送到 Azure Web App 时,却没有。

我最初是通过发布工具推送它的,现在我使用从 Github 分支推送的内置功能。

我有以下内容网络配置:

<system.web>
    <customErrors mode="On" defaultRedirect="~/Error/Index">
      <error redirect="~/Error/NotFound" statusCode="404" />
      <error redirect="~/Error/Index" statusCode="500" />

    </customErrors>
    <!-- More stuff :-) -->
  </system.web>
  <system.webServer>

这是我的错误控制器:

 public class ErrorController : Controller
    {
        public ViewResult Index()
        {
            return View("Error");
        }
        public ViewResult NotFound()
        {
            Response.StatusCode = 404; 
            return View("NotFound");
        }
    }

我的生产 web.config 转换文件根本没有更改(请参阅注释中的内容):

<?xml version="1.0"?>

<!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=301874 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
    finds an attribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB"
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <!--
      In the example below, the "Replace" transform will replace the entire
      <customErrors> section of your Web.config file.
      Note that because there is only one customErrors section under the
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>

然而,虽然我的 404 页面在本地主机中工作得很好,但在生产中我得到:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

而不是一个好看的404页面。

任何想法?


我的本地主机上有一个 404 页面,运行得很好。但是,当它被推送到 Azure Web App 时,却没有。

我使用了你的代码并重现了你的结果。

I add <httpErrors existingResponse="PassThrough" /> to <system.webServer> </system.webServer>在 web.config 中,然后它工作正常。

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <httpErrors existingResponse="PassThrough" />
</system.webServer>

你可以参考这个article https://learn.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/更多细节。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

404 页面适用于本地主机,但不适用于生产(Azure Web App) 的相关文章

  • FluentValidation 集合属性未验证

    这是我第一次尝试实现 FluentValidation 因为我需要涵盖复杂的验证场景 我试图验证的类具有大量属性 复杂对象和多个集合 我没有遇到验证主类的属性的问题 甚至检查集合是否不为空 但在验证每个集合中的对象属性时确实遇到了问题 为了
  • 如何在 MVC 3 Razor View Engine 中使用 C# 显示和隐藏 Div?

    我必须编写 C 代码来在 MVC3 中显示和隐藏 div 以用于基于 C 中的 switch case 的各种控件 如何在不使用 JQuery Show 或 hide 的情况下完成它 但在完全服务器端 将 switch 语句直接添加到 cs
  • 使用 ViewModel 设计 MVC 存储库

    我想创建一个存储库类来将我的数据逻辑与控制器分开 我使用 ViewModel 来表示一些数据 这些数据将填充来自不同表的数据 我有一些问题 对于像这样的方法GetAll 我要返回一个IQueryable
  • ASP.NET Core 中的默认日志级别、系统日志级别和 Microsoft 日志级别是什么

    默认项目模板具有以下日志记录配置appSettings json Logging IncludeScopes true LogLevel Default Debug System Information Microsoft Informat
  • 仅在 Azure Web 应用程序中从 FTP 下载文件失败

    我有一个非常基本的代码 可以从 FTP 服务器下载文本文件列表 foreach var fileUri in files try var ftpRequest FtpWebRequest FtpWebRequest Create fileU
  • 将 Azure Blob 与 Azure 网站连接

    我正在尝试将 Azure 网站连接到 Azure blob 我打算在容器中托管一些文件 然后从我的网站获取它们 我从本教程开始 http azure microsoft com en us documentation articles we
  • 如何使用 VS2010 在开发服务器上测试将 ASP.NET Web 应用程序作为 64 位进程运行?

    我的任务很简单 我需要在我的开发计算机上的 64 位环境中测试我的 ASP NET Web 应用程序 此时 我什至不询问如何通过调试器运行它 我所需要的只是在 64 位进程中运行它 因此 我在 Visual Studio 2010 中创建了
  • 嵌入式剃须刀视图

    最近 我读到一篇post http www chrisvandesteeg nl 2010 11 22 embedding pre compiled razor views in your dll 作者在其中描述了如何将 razor 视图编
  • Azure 表存储和缓存

    是否值得使用 Azure 缓存预览版从 Azure 表存储缓存数据 或者在大型应用程序中表存储是否足够快 Thanks 简短的答案是这取决于 在我当前正在开发的应用程序中 我们使用缓存来处理一些信息来处理从表存储检索数据的延迟并适应每秒所需
  • ASP.NET 4 中 '(单引号)和“(双引号)之间的区别

    我想在 aspx 页面中的服务器控件的代码隐藏中调用 MyMethod 如下所示 我的页面 aspx
  • ASP.net kerberos 偶尔下降到 NTLM

    背景 仅相关部分 我们有一个大型 Intranet asp net 2 0 3 5 应用程序 Web服务器是AD域上的Windows Server 2003 客户端使用 Windows IE 6 8 Windows 身份验证 具有从 Win
  • 使用 javascript 打开文件,客户端

    在我的应用程序中 我想打开客户端计算机上存在的文件 我创建了两个应用程序 桌面应用程序和 Web 应用程序 当用户安装桌面应用程序时 一些文件会被复制到其安装路径 我想通过 javascript 从我的 Web 应用程序打开这些文件 出于安
  • AJAX 将 JavaScript 字符串数组发送到 JsonResult 作为 List 始终返回 Null?

    我正在尝试在 JavaScript 中构建一个字符串数组 并在操作方法的字符串列表中获取结果 下面是我的 JavaScript 的样子 我正在使用 jQuery 1 4 2 问题是我的操作方法中的列表始终显示 NULL JavaScript
  • 信号器 CORS 问题

    在我的服务器端 我使用带有信号器的 Web api 2 在我的客户端 我使用的是 angularjs 这是我启动信号连接时的 http 请求 gt GET gt http example com signalr negotiate clie
  • 动态或在构建时连接和缩小 JavaScript - ASP.NET MVC

    作为这个问题的扩展这里在用户控件中链接 JavaScript 库 https stackoverflow com questions 885990 linking javascript libraries in user controls
  • 将集合传递给 EditorFor() 时,它会为输入元素生成无效名称

    我有一个 BookCreateModel 其中包含书籍的平面信息 例如标题 出版年份等以及书籍作者的集合 复杂类型 public class BookCreateModel public string Title get set publi
  • 多次发生 Web 服务错误

    在许多机器 使用 Asp net 1 和 2 上 我们看到以下带有随机文件名的错误 使用 dll每次我们尝试进行 Web 服务调用时都会生成此扩展名 过去我们不得不重新安装asp net这似乎已经解决了问题 然而 有一次我们尝试获取命令提示
  • 如何使用最小起订量模拟 Controller.User

    我有几个 ActionMethods 查询 Controller User 的角色 如下所示 bool isAdmin User IsInRole admin 在这种情况下可以方便地行事 我开始使用这样的代码对这些方法进行测试 TestMe
  • 使用 Web API 服务作为中央身份验证点

    我对身份管理领域非常陌生 所以请饶恕我 我想要做的是让多个客户端 MVC 应用程序与单个 Web API 应用程序通信 以对其用户进行身份验证 在该 Web API 应用程序中 我想使用 ASP NET Identity 与用户与数据库进行
  • 如何在网格视图中突出显示文本的结果? [复制]

    这个问题在这里已经有答案了 可能的重复 如何突出显示某个单词 https stackoverflow com questions 9546761 how can i highlight a word 我有一个网格视图和一个文本框 用于从列中

随机推荐