【问题标题】:Failed to load resource: the server responded with a status of 500 (Internal Server Error) Azure MVC加载资源失败:服务器响应状态为 500(内部服务器错误)Azure MVC
【发布时间】:2019-12-04 13:10:19
【问题描述】:

我制作了 MVC 项目并将其发布到 Azure 。在 IIS 本地服务器中它工作正常,但在 Azure 上,当它路由删除时,它不会路由到删除视图并停止在删除操作中,而是出现:

当我打开浏览器的控制台时,会出现此问题消息:

加载资源失败:服务器响应状态为 500 (内部服务器错误)

这是代码:

控制器:

  public class GroupsController : Controller
            {
        //the rest of the code
               // GET: Groups
                public ActionResult Index()
            {
                List<GroupsModels> groups = GetJsonFile();
                return View(groups);
            }
                    // GET: Groups/Delete/
                [HttpGet]
                public ActionResult Delete(int id,string groupname,string useremail)
                {
                    GroupsModels temp = new GroupsModels
                    {
                        ID = id,
                        Name = groupname,
                        newuser = useremail
                    };
                    return View(temp);
                }
            }

模型:

public class GroupsModels
{
    public GroupsModels()
    {
        this.UserEmail = new List<string>();
    }
    public int ID { get; set; }
    public string Name { get; set; }
    [EmailAddress(ErrorMessage = "Invalid Email Address")]
    public string newuser { get; set; }
    public List<string> UserEmail { get; set; }
}

索引视图:

@model IEnumerable<DashBoard.Models.GroupsModels>

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

<h2>Roles</h2>


@foreach (var item in Model)
{

    <div class="row  alert-success" style="text-align: center;font-size:large; padding:10px;">
        <div class="col-sm">
            <b> @Html.DisplayFor(modelItem => item.Name) |</b>
            @Html.ActionLink("Add User", "Add", "Groups", new { GroupId = item.ID },null)

        </div>

    </div>

    <div class="row   border-bottom border ">
        @for (int i = 0; i < item.UserEmail.Count(); ++i)
        {

            <div class="col-6 col-md-4  border">
                <b> @Html.DisplayFor(modelItem => item.UserEmail[i])|</b>
                @Html.ActionLink("Delete","Delete","Groups",new { id = item.ID, groupname = item.Name, useremail = item.UserEmail[i] },null)
            </div>
            if (i == 2)
            {

                <div class="w-100"></div>
            }
        }

    </div>

    <br />
}

删除视图:

  @model DashBoard.Models.GroupsModels

@{
    ViewBag.Title = "Delete";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<div>
    <h4>GroupsModels</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
           <b>Group Name</b>
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>

        <dt>
            <B>User Email</B>
        </dt>

        <dd>
            @Html.DisplayFor(model => model.newuser)
        </dd>

    </dl>

    @using (Html.BeginForm()) {
        @Html.AntiForgeryToken()

        <div class="form-actions no-color">
            <input type="submit" value="Delete" class="btn btn-default" /> |
            @Html.ActionLink("Back to List", "Index")
        </div>
    }
</div>

请问有什么问题吗?我该如何解决?

【问题讨论】:

  • 您是否有堆栈跟踪或确切的错误消息,因为 500 太通用了。可能是用于在数据库服务器上执行删除或更新操作的身份权限,也可能是空引用异常..等。
  • 谢谢你,我的朋友,我已经在下面回答了,是的,这是关于索赔的,谢谢。

标签: c# asp.net-mvc azure internal-server-error


【解决方案1】:

代码 500 表示应用程序没有找到您要查找的源代码,可能是控制器或操作名称错误或参数丢失或错误我认为您应该将 ActionLink 更改为:

@Html.ActionLink("Delete","Delete","Groups",new { id = item.ID, groupname = item.Name, useremail = item.UserEmail[i] })

【讨论】:

  • 谢谢你,我的朋友,但实际上我正在使用 MVC 5.2.7.0,并且要指定控制器,你必须像我上面写的那样编写它。
【解决方案2】:

在我关注端到端交易细节后,我发现了这个问题:

类型声明 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' 要么 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' 提供的 ClaimsIdentity 上不存在。启用防伪 基于声明的身份验证的令牌支持,请验证 已配置的声明提供程序在 它生成的 ClaimsIdentity 实例。如果配置的声明 提供者改为使用不同的声明类型作为唯一标识符, 可以通过设置静态属性来配置 AntiForgeryConfig.UniqueClaimTypeIdentifier。

我已经通过将此代码行添加到 Global.asax 来解决它

AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

使用这些:

using System.Security.Claims;
using System.Web.Helpers;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 2014-11-24
    • 2021-07-27
    相关资源
    最近更新 更多