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