Ich bin Anfänger in ASP .NET Core 2.1 und arbeite an einem Projekt, das ASP .NET Core 2.1 mit individueller Authentifizierung verwendet. Ich möchte meine Anmeldeseite als Standardroute anstelle von Startseite/Index festlegen:
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
Jede Hilfe, wie ich es als ASP .NET Core 2.1 als Login ändern kann, wird jetzt als Rasiermesserseite anstelle von MVC Action View verwendet.
Verwenden Sie diese Methode in ConfigureServices .
services.AddMvc().AddRazorPagesOptions(options=> {
options.Conventions.AddAreaPageRoute("Identity", "/Account/Login","");
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
dann in Configure method
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Ich löse dies, indem ich diesen Code in der Funktion ConfigureServices
(Startup.cs) verwende.
services.AddMvc().AddRazorPagesOptions(options => {
options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", "/Account/Login");
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
Verwenden Sie dies einfach in Ihrer Konfiguration. Dadurch wird AuthorizeAttribute zu Ihrer Seite hinzugefügt
services.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizePage("/Home/Index");
});
Oder ändern Sie die Standardroute wie folgt:
services.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/Employees/Index", "");
});
Sehen Sie sich diese Seite ggf. an: https://docs.Microsoft.com/fr-fr/aspnet/core/security/authorization/razor-pages-authorization?view=aspnetcore-2.1
dies kann helfen, ich hatte keine Notwendigkeit, die Standardseite selbst zu ändern
https://exceptionnotfound.net/setting-a-custom-default-page-in-asp-net-core-razor-pages/