Middleware with ASP.NET MVC and .NET 4.5

1

Is it possible to add some middleware 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 in 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 PHP code break is just to exemplify my question.

    
asked by anonymous 24.02.2016 / 20:20

1 answer

1

In ASP.NET MVC there is no such concept of "middleware". What exists are user architectures and authentication that can be incorporated into the application, which is an approach that I believe is close to Laravel's middleware .

Authentication is usually checked through attributes, which may be native or written by the application programmer. To write your own attribute or understand how authentication is done, you can get for the answers from here . or go to the main ASP.NET MVC user authentication and authentication tutorials, Identity .

There are also other architectures, older or developed by third parties, like the ASP.NET Membership or Identity Manager .

    
24.02.2016 / 23:25