我正在尝试在 MVC 3 上(特别是在 Azure 上)设置自定义维护页面。基本上为了保持 SEO 友好,我需要返回 503(服务不可用)。我的所有其他自定义错误页面都在 Azure 中工作(例如 404),遵循通常的
<customErrors mode="On">
<error statusCode="404" redirect="404.htm"/>
<error statusCode="503" redirect="503.htm"/>
</customErrors>
404 页面有效,但 503 页面没有遵循,我只是得到一个丑陋的服务不可用页面。我通过 error.cshtml 和标准 HandleErrorAttribute 使 500 错误正常工作。
我什至尝试使用以下方法从 ActionFilter 返回我自己的 ActionResult
public class SiteDownForTestingResult : ActionResult
{
public SiteDownForTestingResult() : base()
{
}
public override void ExecuteResult(ControllerContext context)
{
var path = System.Web.Hosting.HostingEnvironment.MapPath("~/app_testing.htm");
var response = context.HttpContext.Response;
response.Clear();
response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
response.StatusDescription = "Service Unavailable.";
response.WriteFile(path);
response.End();
}
}
如果app_testing是我的自定义页面,然后从ActionFilter的OnActionExecuting中设置filterContext.Result = new SiteDownForTestingResult();
,我仍然会看到简单的503“服务不可用”页面
这是否与 Azure 上的 application.config 锁定某些我不知道的内容有关。这在 IIS7 和我的本地机器上运行良好,但模拟器和云都没有带来任何乐趣。
如有任何帮助,我们将不胜感激。
最佳答案
根据我的理解,自定义 503 错误主要是在应用程序池不可用时直接从 https.sys 生成的。现在,当没有应用程序池时,您的任何设置都将不起作用,因为您的自定义错误设置将特定于应用程序池。此外,大多数搜索引擎都依赖于 503 错误代码返回,以便正确显示搜索结果,这就是为什么通常不在应用程序级别自定义此错误的原因。
当您引用 Windows Azure 模拟器时,我相信您正在使用 Windows Azure Web 角色。借助 Windows Azure Web 角色,您可以在启动任务中使用 AppCmd.exe 自定义 IIS,这是您的最大自定义级别。您无法在 Windows Azure 中达到 HTTP.sys 自定义级别,因此自定义 503 错误可能无法在 Windows Azure 上运行。
关于asp.net-mvc-3 - 如何为 Azure 创建返回 503 的自定义维护页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11366346/