【发布时间】: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