アプリケーションのASP.NETコア2に認証を提供します。 アカウント/ログインのデータを含むモデルを送信した後、 "await Authenticate(user) "エラーメッセージが表示されます。 説明が不足している箇所はわかりません。AS.NETコア2スキームを処理する認証ハンドラが設定されていません
Startup.cs
//ConfigureServices
services.AddAuthentication(options =>
{
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie("TmiginScheme", options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.ExpireTimeSpan = TimeSpan.FromHours(1);
options.SlidingExpiration = true;
});
//Configure
app.UseAuthentication();
AccountController
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel model)
{
if (ModelState.IsValid)
{
User user = null;
Cryptex cryptex = new Cryptex();
string password = cryptex.EncryptText(model.Password, "TMigin");
// Ищем user
user = fStorage.Users.GetUserByLogin(model.Login);
if (user != null)
{
if (string.Compare(user.Password, password) != 0)
{
user = null;
}
}
if (user != null)
{
await Authenticate(user);
return RedirectToAction("Index", "CMS");
}
else
{
// Логируем ошибку входа
ModelState.AddModelError("", "Ошибка входа");
}
}
return View(model);
}
private async Task Authenticate(User user)
{
var claims = new List<Claim>
{
new Claim(ClaimsIdentity.DefaultNameClaimType, user.Name),
new Claim("CMS", "True")
};
var identity = new ClaimsIdentity(claims);
var principal = new ClaimsPrincipal(identity);
await HttpContext.Authentication.SignInAsync("TmiginScheme", principal);
}
は私がapp.UseMvc(後にコードを置いて、動作していない
。私は固体の8時間以上のものを試してきましたが、これは修正されたことが判明しました。 –