如何 pass-through 在 Azure 中自定义 HTTP 401 的内容?

How to pass-through custom content of an HTTP 401 in Azure?

我有一个在 HTTP 401 上提供自定义内容的应用程序。从 AuthorizeAttribute 继承的授权过滤器包含如下方法:

protected override void HandleUnauthorizedRequest(
    AuthorizationContext filterContext)
{
    filterContext.HttpContext.Response.Clear();
    filterContext.HttpContext.Response.StatusCode =
        (int)HttpStatusCode.Unauthorized;
    filterContext.HttpContext.Response.Write("Custom content goes here.");
    filterContext.Result = new HttpUnauthorizedResult();
}

当 运行 本地应用程序访问受保护资源时,自定义内容显示成功。

部署到 Windows Azure 后,应用程序只显示:

You do not have permission to view this directory or page.

header还是正确的HTTP/1.1 401 Unauthorized,但是我设置的内容不见了

如何防止 Azure 干扰我的应用程序和 pass-through 从 Responde.Write 通过 HTTP 到客户端的内容?

与 IIS 一样,添加:

filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;

问题已解决。使用此指令,自定义内容现在显示给客户端。