简体   繁体   English

无法加载资源:服务器响应状态为 500(内部服务器错误)Azure MVC

[英]Failed to load resource: the server responded with a status of 500 (Internal Server Error) Azure MVC

I've made MVC project and published it to Azure .我已经制作了 MVC 项目并将其发布到 Azure 。 in the IIS local server it works fine, but on Azure when it's routing to delete it does not route to the delete view and stop in Delete action and this appears instead :在 IIS 本地服务器中它工作正常,但在 Azure 上路由删除时它不会路由到删除视图并停止在删除操作中,而是出现:

文本

and when I open the console of the browser this problem message appears :当我打开浏览器的控制台时,会出现此问题消息:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)加载资源失败:服务器响应状态为 500(内部服务器错误)

this is the code :这是代码:

the controller :控制器:

  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);
                }
            }

the Model :该模型 :

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; }
}

Index view :索引视图:

@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 />
}

delete view :删除视图:

  @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>

What's the problem please?请问有什么问题? And how can I fix it?我该如何解决?

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

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

after I've followed the End-to-end transaction details I've found this problem :在我遵循端到端交易细节之后,我发现了这个问题:

A claim of type ' http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier ' or ' http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider ' was not present on the provided ClaimsIdentity.类型为“ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier ”或“ http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider ”的声明是不存在于提供的 ClaimsIdentity 中。 To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates.要通过基于声明的身份验证启用防伪令牌支持,请验证配置的声明提供程序是否在它生成的 ClaimsIdentity 实例上提供这两个声明。 If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.如果配置的声明提供程序使用不同的声明类型作为唯一标识符,则可以通过设置静态属性 AntiForgeryConfig.UniqueClaimTypeIdentifier 进行配置。

and I've solved it by adding this code line to Global.asax我已经通过将此代码行添加到 Global.asax 解决了这个问题

AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

using these :使用这些:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载资源失败:服务器响应状态为500(内部服务器错误 - Failed to load resource: the server responded with a status of 500 (Internal Server Error 加载资源失败:服务器响应状态为500(内部服务器错误)asp.net - Failed to load resource: the server responded with a status of 500 (Internal Server Error) asp.net jQuery ajax调用将无法访问控制器:无法加载资源:服务器以状态500(内部服务器错误)响应 - Jquery ajax call wont access the controller: Failed to load resource: the server responded with a status of 500 (Internal Server Error) 加载资源失败:服务器响应状态为 500(内部服务器错误),同时从控制器返回 base64 格式的图像 - Failed to load resource: the server responded with a status of 500 (Internal Server Error) while returning image in base64 format from controller 加载资源失败:服务器响应状态为 500(内部服务器错误) - failed to load resource: the server response with a status 500 (internal server error) 无法加载资源:服务器使用Ajax响应状态为500 - Failed to load resource: the server responded with a status of 500 using Ajax Ajax 调用“加载资源失败:服务器响应状态为 500” - Ajax call with a 'failed to load resource : the server responded with a status of 500' 加载资源失败:服务器响应状态为 500 () asp.net mvc - Failed to load resource: the server responded with a status of 500 () asp.net mvc 加载资源失败:服务器响应状态为 500 () | Oracle &amp; ASP.NET 核心 MVC 3.1 - Failed to load resource: the server responded with a status of 500 () | Oracle & ASP.NET Core MVC 3.1 错误:无法加载资源:服务器的状态为400(错误请求) - Error:Failed to load resource: the server responded with a status of 400 (Bad Request)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM