سلام
بعد از اینکه کاربر لاگین میکنه و به صفحه home هدایت میشه اونجا وقتی چک میکنم کاربر لاگین کرده، شرط fail میشه و دوباره میره صفحه لاگین
{ public async Task<IActionResult> Index() { if (User.Identity.IsAuthenticated) { return View(); } else { return RedirectToAction("Login", "Security"); } } }
کد لاگین :
public async Task<IActionResult> Login(PLIMO.Domain.ViewModel.LoginModel model, string returnUrl) { //model.PasswordHash if (!ModelState.IsValid) return View(model); var result = await this.signInManager.PasswordSignInAsync( model.UserName, model.Password, isPersistent: false, lockoutOnFailure: false); if (result.Succeeded) //اینجا رو با دیباگر تست گرفتم که success میده { // User.Identity.IsAuthenticated = true; return RedirectToAction("Index", "Home"); } ModelState.AddModelError(string.Empty, "Login Failed"); return View(model); }
کد تابع IConfigure از فایل startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddMvc() .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); services.AddIdentity<Personnel, PersonnelRole>(options => { options.Password.RequiredLength = 6; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireDigit = false; }) .AddEntityFrameworkStores<PLIMODbContext>() .AddDefaultTokenProviders(); services.AddSession(); services.AddMemoryCache(); services.ConfigureApplicationCookie(options => { options.LoginPath = "/Security/Login"; options.LogoutPath = "/Security/Logout"; options.AccessDeniedPath = "/Security/AccessDenied"; options.SlidingExpiration = true; options.Cookie = new CookieBuilder { HttpOnly = true, Name = ".Fiver.Security.Cookie", Path = "/", SameSite = SameSiteMode.Lax, SecurePolicy = CookieSecurePolicy.SameAsRequest }; }); services.AddKendo(); services.AddDbContext<PLIMODbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("PLIMODbContext")) , ServiceLifetime.Scoped); services.AddTransient<IOrganization, OrganizationRepo>(); }
کد تابع Configure از قایل Starup.cs public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseMvcWithDefaultRoute(); app.UseMvc(routes => { routes.MapRoute( name: "areas", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}" ); }); app.UseStaticFiles(); app.UseAuthentication(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseKendo(env); app.UseSession(); }
app.UseAuthentication();
باید بزارید
app.UseAuthentication();
رو توی configure گذاشتم
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)