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();
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With