gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:31:29 25 4
gpt4 key购买 nike

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

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

我有以下web.config:

<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>

这是我的错误 Controller :

 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 页面。

有什么想法吗?

最佳答案

I have a 404 page on my localhost which works just fine. However, when it's pushed to Azure Web App, it does not.

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

我添加<httpErrors existingResponse="PassThrough" /><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>

enter image description here

可以引用这个article了解更多详情。

关于asp.net - 404 页面适用于本地主机,但不适用于生产(Azure Web App),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49274235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com