سلام به همه
در ویژال 2017 و asp core 2.2 پروژه ای رو انجام دادم و بخش ورود کاربر را با Claim انجام دادم و مشکلی وجود نداره و کار میکنه به صورت زیر :
if (mdl.IsEnable) { var claims = new List<Claim>() { new Claim(ClaimTypes.Name,mdl.UserName), new Claim(ClaimTypes.NameIdentifier,mdl.Id.ToString()), new Claim(ClaimTypes.IsPersistent,login.IsRemmember.ToString()) }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var pricipal = new ClaimsPrincipal(identity); var properties = new AuthenticationProperties() { IsPersistent = login.IsRemmember }; HttpContext.SignInAsync(pricipal, properties); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } return Redirect("/"); } else { ViewBag.ErrorMessage = Resource_Fa.UserNotFound; }
و در پارشیال لاگین به این صورت
@if (User.Identity.IsAuthenticated) { <a asp-action="Profile" asp-controller="Home"><span id="UserName"> @User.Identity.Name </span></a> <a class="Shake" asp-action="LogOff" asp-controller="Account" asp-area=""><span> خروج</span></a> } else { <a class="Shake" asp-action="Login" asp-controller="Account"> <span> ورود </span> </a> <a class="Shake" asp-action="Register" asp-controller="Account"> <span> ثبت نام </span> </a> }
و مشکل اینجاس ، بعد ارتقا به نسخه ویژوال 2019 و Asp core 3 همین کد ها رو در پروژه ای جدید نوشتم اجرا میشه ولی زمانی @if (User.Identity.IsAuthenticated) برررسی میکنم همیشه false میده
راهنمایی بفرمایین
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)