// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { AuthorizeManagement.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); // 需要加入這一行 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Account}/{action=Index}/{id?}"); }); }
public async Task <JsonResult> Login(LoginRequest form) { await AuthorizeManagement.SignOutAsync(); if (form.LoginId != "test" || form.Password != "1234") { return(Json(new { result = false })); } await AuthorizeManagement.SignInAsync(form.LoginId); return(Json(new { result = true })); }
public static IServiceCollection AddAuthorize(this IServiceCollection services, Action <AuthorizeOptionsBuilder> action = null) { var builder = new AuthorizeOptionsBuilder(); action?.Invoke(builder); var options = builder.Build(); var management = new AuthorizeManagement(options); services.AddSingleton <IAuthorizeManagement>(management); services.AddSingleton <IPermissionManagement, PermissionManagement>(); Type permissionType = builder.GetPermissionType(); if (permissionType != null) { services.AddSingleton(typeof(IPermissionModule), permissionType); } services.AddMvc(x => { x.Filters.Add <AuthorizeFilter>(); }); return(services); }
public async Task <IActionResult> LogOut() { await AuthorizeManagement.SignOutAsync(); return(RedirectToAction("Index")); }