MissingMethodException: 找不到方法:'Boolean

4

帮我解决当我运行ASP.NET项目时出现的错误。

MissingMethodException: Method not found: 'Boolean Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.CryptProtectData(Microsoft.AspNetCore.Cryptography.DATA_BLOB*, IntPtr, Microsoft.AspNetCore.Cryptography.DATA_BLOB*, IntPtr, IntPtr, UInt32, Microsoft.AspNetCore.Cryptography.DATA_BLOB ByRef)'.

当我在我的 .NET 6 项目中使用 <login> 进行登录时,无法加载布局,请帮帮我。

enter image description here

Login.cshtml

<form method="post">
    <div class="col-12">
        <div class="mb-3">
            <label class="form-label">Email</label>
            <input type="email" class="form-control" id="yourUsername" name="username"/>
            <div id="ErrorEmail" style="color: red;" class="form-text"></div>
        </div>
    </div>

    <div class="col-12">
        <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">Mật Khẩu</label>
            <input type="password" class="form-control" id="yourPassword" name="password" />
            <div id="ErrorPassword" style="color: red;" class="form-text"></div>
        </div>
    </div>
    <div class="col-12">
        <button class="btn btn-primary w-100" id="Btn_Login" type="submit">Đăng Nhập</button>
    </div>
</form>

账户控制器

[HttpPost]
public async Task<IActionResult> Login(string username, string password, string ReturnUrl)
{
    if ((username == "Admin@gmail.com") && (password == "Admin"))
    {
        var claims = new List<Claim>
        {
            new Claim(ClaimTypes.Name, username)
        };

        var claimsIdentity = new ClaimsIdentity(claims, "Login");

        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
        return RedirectToAction("Index", "Home");
    }
    else
        return View();
}

我希望能得到一个好的解决方案


你的目标项目设置是Core 7吗? - jdweng
当您在针对.NET6的Web应用程序中使用需要.NET7的Nuget软件包时,就会发生这种情况。请使用较早版本的软件包进行修复。https://github.com/dotnet/aspnetcore/issues/45149 - Hans Passant
3个回答

0

将项目属性中的目标平台翻译为 .net 7


目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

0
这个问题是由于安装包的版本与项目的目标框架不匹配所导致的。 你可以将目标设置为 .net 7 并更新已安装的包。

1
所以现在你基本上只是复制了其他人几个月前(四月和六月)已经回答过的内容,没有太多原创性。 - Peter B

0
检查您正在使用的.NET Core版本,并确保项目中的所有NuGet包与此版本兼容。例如,如果您使用的是.Net6,则您的包不能是7.0等版本,并确保所有包的版本相同。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接