Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to handle multiple actions?

Like most web applications you have a method that gets called when you log in. There are a few things that may need to get done when logged in and over time this may increase. eg. logging, welcome emails, maintenance.

Should events be used to do this or is there a better way?? I'm using C# and ASP.net MVC.

Update
This is already in its on Service Layer class. eg.

  public void Login(User user)
        {
            SetAuthCookie(user);
            LogLogin(user, true);
            SendEmails();
        }
like image 687
Schotime Avatar asked Nov 05 '22 12:11

Schotime


1 Answers

Extract the application logic to separate classes. Your application will be easier to work with if you keep the controllers as thin as possible.

The Post, Redirect, Get pattern is effective for MVC. A good post about this from my bookmarks collection is: http://www.eworldui.net/blog/post/2008/05/ASPNET-MVC---Using-Post2c-Redirect2c-Get-Pattern.aspx

I would also recommend looking into Action Filters. Robert Conery has a good introduction to using action filters on his blog at http://blog.wekeroad.com/blog/aspnet-mvc-securing-your-controller-actions/ . The post is authentication-specific, but the concepts can be extrapolated to whatever type of functionality you want to implement.

like image 118
smartcaveman Avatar answered Nov 15 '22 05:11

smartcaveman