【问题标题】:Azure .Net MVC Custom Response.StatusDescription are not sentAzure .Net MVC 自定义 Response.StatusDescription 未发送
【发布时间】:2018-06-06 12:46:33
【问题描述】:

我尝试使用自定义 StatusDescription 将消息与我的内容一起发送给客户端。在我的本地机器上它可以工作,但在 Azure 上却不行。有人知道为什么吗?

问候,亚历克斯

更新:

[HttpPost]
[ValidateAntiForgeryToken(Order = 1)]
public ActionResult SaveCustomer(KundenViewModel viewModel)
{

    /*
     * Do some additional stuff here
     */

    try
    {
        // Save the customer in database
        SaveCustomerToDatabase(viewModel);
        Response.StatusCode = (int)HttpStatusCode.OK;
        Response.StatusDescription = Global.SaveCustomerSuccess; // <---  Try to response a message
        return PartialView("_CustomerTable", GetCustomerViewModel();
    }
    catch (Exception e)
    {
        Logger.LogException(e, HttpContext);
        Response.StatusCode = (int)HttpStatusCode.InternalServerError;
        Response.StatusDescription = Global.GeneralErrorInternal; // <---  Try to response a message
        return null;
    }
}

在客户端我尝试显示消息:

MyNamespace.customerSaveSuccess = function (data, textStatus, jqXHR) {
    MyNamespace.Notification.Success(jqXHR.statusText);
    _ToggleTabs(false);
};

如果我在本地尝试它会完美运行,但一旦我将它发布到 Azure,我只会收到默认状态代码消息“OK”而不是我的自定义文本

【问题讨论】:

  • 如果没有看到您的任何自定义代码,我们怎么可能知道?
  • 简而言之:不。再长一点:请确保我们可以检查您遇到的情况,例如通过添加(相关)代码。更多信息请参考这篇文章:minimal reproducible example
  • @rickvdbosch OP 提供了一些代码。

标签: c# asp.net-mvc azure


【解决方案1】:

我在 web.config 中的 httpErrors 元素中添加了“existingResponse”属性,以允许响应正文传递到 Azure 中的客户端。我遇到了同样的问题,我只能在本地看到消息。希望这会有所帮助!

<system.webServer>
    <httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough" />

【讨论】:

    猜你喜欢
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 2021-04-08
    • 1970-01-01
    • 2022-08-02
    • 1970-01-01
    相关资源
    最近更新 更多