0
사실 나는 인증 관련 항목이 충분하지 않아서 ".Net Core 2.0"에 사용자 정의 인증을 포팅하려고하는데 도움이 필요합니다. 저기 몇 가지 유사한 질문이 있지만 광산은 조금 다릅니다. 사용자는 쉽게 로그인하여 프로젝트에 로그 아웃 할 수 있으며 로그인하지 않은 시간의 로그인 URL을 설정해야하며 로그인 페이지로 리디렉션해야합니다.ASP.Net MVC 코어 2.0에서 로그인 URL 설정
이미 (this, this 또는 여러 개의 다른 페이지를하지만, 대부분 구식 - 이전 버전 관련 - 또는 내 경우에 맞지 않는) 확인했다 내 Startup.cs :
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddMvc(options => {
options.ModelBinderProviders.Insert(0, new Olive.Mvc.OliveBinderProvider());
})
.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
})
.ConfigureApplicationPartManager(manager =>
{
var oldMetadataReferenceFeatureProvider = manager.FeatureProviders.First(f => f is MetadataReferenceFeatureProvider);
manager.FeatureProviders.Remove(oldMetadataReferenceFeatureProvider);
manager.FeatureProviders.Add(new ReferencesMetadataReferenceFeatureProvider());
}); ;
services.AddSingleton<IUserStore<User>, UserStore>();
services.AddSingleton<IRoleStore<string>, RoleStore>();
services.AddIdentity<User, string>();
services.AddAuthentication(IdentityConstants.ApplicationScheme)
.AddCookie(opt => opt.LoginPath = "/login");
// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();
services.AddSession();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseAuthentication();
app.UseStaticFiles();
app.UseSession();
app.UseMvc(routes =>
{
//routes.MapRoute(
// name: "default",
// template: "{controller=Home}/{action=Index}/{id?}");
});
}
보호 할 Controller 및 Action 메서드에 Authorize 특성을 추가 했습니까? – ssimeonov
예. 문제는 사용자가 잘못된 URL ("/ Login"보다는 "/ Account/Login")으로 리디렉션된다는 것입니다. –
https://stackoverflow.com/a/45922216/9604 help? – mxmissile