asp.net样板:值不能为null。参数名称:键

时间:2018-12-30 10:07:02

标签: asp.net-mvc asp.net-core asp.net-boilerplate

我正在尝试在db中创建记录,但在下面出现此错误。

its image of error page buy may not work

这是错误

 ArgumentNullException: Value cannot be null.
 Parameter name: key
System.Collections.Generic.Dictionary<TKey, TValue>.FindEntry(TKey key)
Microsoft.AspNetCore.Http.Internal.RequestCookieCollection.ContainsKey(string key)
Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter.ShouldValidate(AuthorizationFilterContext context) in AbpAutoValidateAntiforgeryTokenAuthorizationFilter.cs
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ValidateAntiforgeryTokenAuthorizationFilter.OnAuthorizationAsync(AuthorizationFilterContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

这是我的控制者:

  public IActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public  IActionResult Index(CreateUserInput input)
    {
        if (HttpContext.Request.Cookies.ContainsKey(".AspNetCore.Antiforgery."))
        {
            _userAppService.Create(input);
        }

        return RedirectToAction("Index","Home");
    }

这是我的html页面:

  @model DutyV2.Users.DTO.CreateUserInput
@{
    ViewData["Title"] = "Index";
}

<h2>Index</h2>
<form asp-action="Index" method="post">
    <div class="input-group">
        <label class="control-label" asp-for="Name"></label>
        <input asp-for="Name" class="form-control" type="text" />
    </div>
    <div class="input-group">
        <label class="control-label" asp-for="Email"></label>
        <input asp-for="Email" class="form-control" type="email" />
    </div>
    <input type="submit" value="Create"/>
</form>

1 个答案:

答案 0 :(得分:1)

将您的ABP版本更新到v4.0.1或更高版本。

如果不使用Cookie身份验证,是由于ContainsKeynull调用了。

该错误发生在AbpAutoValidateAntiforgeryTokenAuthorizationFilterAbpValidateAntiforgeryTokenAuthorizationFilter中。

相关的提取请求:https://github.com/aspnetboilerplate/aspnetboilerplate/pull/3986