【问题标题】:Page load on localhost but not in Azure website - Erro 500页面加载在 localhost 但不在 Azure 网站中 - 错误 500
【发布时间】:2015-05-18 21:34:07
【问题描述】:

我在 Windows Azure 上部署了一个 asp.net mvc 4 应用程序,当我在 localhost 中测试应用程序时一切正常,但是在 azure 网站中,有一个视图返回错误 500,我不知道为什么会这样,你能帮我看看吗?

这是视图:

@model IEnumerable<TestTcc2.Models.Musica>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutMusico.cshtml";
}

<script src="Content/audiojs/audio.min.js"></script>
<div class="row">
<div class="col-md-4"></div>
<div id="divAudio" class="col-md-4">

    <audio id="audioPlay" src="x" preload="auto" onplay="true" />
    <script>
        audiojs.events.ready(function () {
            var as = audiojs.createAll({
                autoplay: true,
                autoload: "none"
            });

        });

        function replaceAll(str, de, para) {
            var pos = str.indexOf(de);
            while (pos > -1) {
                str = str.replace(de, para);
                pos = str.indexOf(de);
            }
            return (str);
        }

        function getUrlParameter(sParam) {
            var sPageURL = window.location.search.substring(1);
            var sURLVariables = sPageURL.split('&');
            for (var i = 0; i < sURLVariables.length; i++) {
                var sParameterName = sURLVariables[i].split('=');
                if (sParameterName[0] == sParam) {
                    var rep = replaceAll(sParameterName[1], "%2F", "/");
                    rep = replaceAll(rep, "%20", " ");
                    return rep;
                }
            }
        }
        var x = getUrlParameter('path');
        $('#audioPlay').attr('src', x);
    </script>
</div>
<div class="col-md-4"></div>
</div>
<br />
<p>
    @Html.ActionLink("Create New", "Create")
</p>

<table class="table table-hover table-bordered">
    <tr>
        <th>
            <span>Genero</span>
        </th>

        <th>
            <span>Nome</span>
        </th>
        <th>
            <span>Artista</span>
        </th>
        <th>
            <span>Preço</span>
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    if (item.UserId == Int32.Parse(Membership.GetUser().ProviderUserKey.ToString()))
    {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.genero.Nome)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Nome)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.NomeArtista)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Preco)
        </td>
        <td>
            @Html.ActionLink("Play", "", new { path = item.path }) |
            @Html.ActionLink("Edit", "Edit", new { id=item.MusicaId }) |
            @Html.ActionLink("Download", "Download", new { path = item.path }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.MusicaId })
        </td>
    </tr>
}
}

</table>

这里是调用视图的控制器方法:

public ActionResult Index()
{
        var musicas = db.Musicas.Include(m => m.genero);
        var _arquivos = modelMusica.listaMusica();
        return View(musicas.ToList());
}

我尝试进行调试,但在 localhost 中显示任何错误,在 azure 中显示以下消息:

错误。处理您的请求时发生错误。

在我的 web.config 中,我将 CustomErrors 设置为关闭并将调试设置为 false。

更新----

大家好,我从 Azure 获取DetailedError:

Detailed Error Information:
Module    ManagedPipelineHandler 
Notification    ExecuteRequestHandler 
Handler    System.Web.Mvc.MvcHandler 
Error Code    0x00000000 
Requested URL    http://independentmusicstore:80/Music 
Physical Path    D:\home\site\wwwroot\Music 
Logon Method    Forms 
Logon User    pedro 

【问题讨论】:

  • 设置 debug=true - 另外,您确定可以访问数据库吗?将数据库访问放在 try-catch 子句中,并使用 ViewBag 将消息(来自异常)写入 catch 中的视图
  • 对。我知道我可以访问数据库,因为我可以注册一个用户。 viewBag 必须显示在错误消息中,对吗?你能举个例子吗?

标签: c# asp.net-mvc azure razor azure-web-app-service


【解决方案1】:

您是否在 eventlog.xml 中看到错误?使用http://blogs.msdn.com/b/waws/archive/2014/09/24/azure-website-siteextension-to-view-eventlogs.aspx 中提到的步骤检查事件日志或直接转到 yourazuresitename.scm.azurewebsites.net/support 然后选择您的站点并选择 -> 分析,然后单击事件查看器...

应在事件查看器中记录作为 HTTP 500 冒泡的未处理异常。如果您在事件日志中看不到任何条目,则通过转到站点启用详细错误 -> 在 azure 门户中配置并在 d:\home\logfiles 文件夹下查找详细错误文件夹(您可以通过 kudu 或 ftp 访问此文件夹)

【讨论】:

  • 谢谢@puneet 我没有看到这个功能,我会在这里为你添加和发布更新
  • 嘿@PuneetGupta 我在日志上看到这条消息:Exception information: Exception type: HttpParseException Exception message: The if block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup. 但是你可以看到,在我提出的主题中,没有任何语法错误......
  • 这显示了错误...只需确保将视图替换为工作副本并仔细检查以确保部署了正确的代码
  • 对,但是,正如您在我发布的视图中看到的那样,一切正常,并且 VS 的构建正在通过,并且没有显示任何错误。
  • 您是否看到错误消息中突出显示的行号???我认为剃刀语法没有将 { 或 } 解释为服务器端代码,这可能是您收到此错误的原因。尝试在 web.config 中将 DEBUG 设置为 TRUE 并在 DEBUG 配置中发布项目(不是发布)并尝试再次运行该页面,这一次错误消息将包含发生问题的确切行号,
【解决方案2】:

【讨论】:

  • 嗨@viperguynaz,我尝试进行调试,但是,当我放置断点时,消息显示在VS2012 The breakpoint will not currently be hit. No symbols have been loaded for this document中。我没有找到解决方案
  • 远程调试需要VS2013。
  • 嗯,在这个链接中也有 Visual Studio 2012 的教程,我试过了,但没有用。我去下载vs2013
【解决方案3】:

试试这个:

导航到您的网站 >> 配置选项卡:

  1. 滚动到应用程序诊断 >> 启用应用程序日志记录(仅限文件系统)
  2. 滚动到站点诊断 >> 启用 Web 服务器日志记录(文件系统)、启用详细的错误消息、启用失败的请求跟踪、启用远程调试(如果您想使用 VStudio 进行调试)

返回您的网站仪表板并快速浏览一下 FTP 主机名 >> 输入您的凭据 >> 检查日志文件

您还可以使用 Kudu 控制台下载日志、查看流、更改应用设置等:

只需输入

https://<yourwebsitename>.scm.azurewebsites.net
  • 工具 >> 日志流
  • 诊断转储(下载日志)
  • 调试控制台 >> CMD 或 Powershell

【讨论】:

    【解决方案4】:

    我注意到的一件事是您正在控制器方法中访问您的数据库。 Azure 部署中的连接字符串设置是否正确?如果将本地数据库测试连接字符串部署到 Azure,可能会导致 500 错误。

    【讨论】:

    • 是的,我在 web.config 中设置了到 localhost 和 Azure SQL 数据库的连接字符串。在 localhost 一切都在运行,但在天蓝色环境中我可以注册新用户,但是当我使用特定类型的用户登录时返回错误 500
    猜你喜欢
    • 2020-03-16
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2021-09-05
    • 2018-02-20
    • 1970-01-01
    • 2017-07-27
    相关资源
    最近更新 更多