1
It is possible to add some middleware the routes that will, for example, allow or redirect a user to access the admin panel, which if not authenticated will be redirected to the login area? as in the example below (In PHP / Laravel):
Route::get('/login', [
'as' => 'login',
'uses' => 'Auth\LoginController@Index',
'middleware' => ['guest', 'throttle:12,1'],
]);
My routes on ASP.NET:
routes.MapRoute(
name: "Admin.Login", url: "admin/login",
defaults: new { controller = "Authentication", action = "Index" },
namespaces: new[] { "Controllers.Admin.Authentication" }
);
routes.MapRoute(
name: "Admin.Login.Attempt", url: "admin/login/attempt",
defaults: new { controller = "Authentication", action = "Attempt" },
namespaces: new[] { "Controllers.Admin.Authentication" }
);
Note: my question is about routes in ASP.NET, the code section in PHP is only to illustrate my question.
What would that "middleware"?
– Leonel Sanches da Silva
Middleware is an intermediate class between Route and Controller, where we can, for example, check if the user is authenticated when trying to access the admin panel, and if not, middleware returns a redirect to a defined route, as the login, preventing the user from proceeding without logging in.
– Rafael Alexandre