I just created my first C# Razor MVC3 project. I’ve dabbled in it before but this is the first time I created one.
Anyhow, I have a simple question. I am using the MembershipProvider AspNetSqlProfileProvider that was build with the default project.
My question is simple, where and how do I check if the user is logged on before it loads the Home/Index.cshtml so that I can direct them to another page?
If they are logged on, I want to take them to the customer portal.
If they are not logged on, I want to take them to the logon screen.
A more generic way to set this up would involve 2 steps:
First, add an [Authorize] attribute to your action that you are securing:
This will make sure that the user has authenticated (using FormsAuthentication).
Second, in your Web.config file, set the URL that you want the user to be redirected to when they need to login.