C# 授权asp.net内核时遇到的问题
请帮帮我吧 我在MS VS 2017中创建了新的应用程序。类型ASP.NET Core 2 MVC 我找不到解决我的问题的办法C# 授权asp.net内核时遇到的问题,c#,asp.net-core-mvc,C#,Asp.net Core Mvc,请帮帮我吧 我在MS VS 2017中创建了新的应用程序。类型ASP.NET Core 2 MVC 我找不到解决我的问题的办法 我加入了创业公司 public void ConfigureServices(IServiceCollection services) { services.AddScoped<USDb, USDb>(); services.Scan(scan => scan.FromAssemblyOf<USDb>()
public void ConfigureServices(IServiceCollection services) {
services.AddScoped<USDb, USDb>();
services.Scan(scan => scan.FromAssemblyOf<USDb>()
.AddClasses()
.AsImplementedInterfaces());
InjectionContainer = services.BuildServiceProvider();
services.AddMvc();
//Auth
services.AddAuthentication(o => {
o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => {
o.LoginPath = new PathString("/Account/Login");
o.ReturnUrlParameter = "RedirectUrl";
o.AccessDeniedPath = new PathString("/Account/AccessDenied");
o.LogoutPath = new PathString("/Account/Logout");
o.ExpireTimeSpan = TimeSpan.FromDays(1);
o.SlidingExpiration = true;
o.Cookie.SameSite = SameSiteMode.Strict;
o.Cookie.Name = ".USAUTH";
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
} else {
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseAuthentication();
}
我不知道该做什么(()请帮助()我失去了希望(你必须在
app.UseMvc(…)之前调用app.usedauthentication();
)
平淡无奇的错误,但不久前升级到asp.net core 2.0后,我遇到了同样的问题。很高兴它帮助mate。
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel model, string redirectUrl = null) {
if (ModelState.IsValid) {
await Authenticate("login");
return Redirect(redirectUrl);
}
return View();
}
private async Task Authenticate(string userName) {
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id));
}