我已经制作了MVC项目并将其发布到Azure。在IIS本地服务器上可以正常工作,但是在Azure上路由删除时,它不会路由到Delete视图并在Delete操作中停止,而是出现:
当我打开浏览器的控制台时,出现此问题消息:
无法加载资源:服务器响应状态为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>
请问是什么问题?我该如何解决?
答案 0 :(得分:1)
代码500表示该应用未找到您要查找的源,可能是控制器或操作名称错误或参数缺失或错误,我认为您应该将ActionLink更改为此:
@Html.ActionLink("Delete","Delete","Groups",new { id = item.ID, groupname = item.Name, useremail = item.UserEmail[i] })
答案 1 :(得分:1)
在我遵循了端到端交易详细信息之后,我发现了这个问题:
类型的声明 '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;