Do you need to do it like this? You should check if you can use asp.net authentication, authorization and membership services. (They are automatically generated when you create a new ASP.NET MVC 3 application [when you leave the "Internet application" checked]).
Then you can use annotation for controllers and actions: (pseudocode):
This allows access to the controller to authorized users only (you can even specify which users or roles are allowed): [Authorize (Roles = "Administrators")]
[Authorize] controller{.....}
And to check if the user is registered, there is already a User property with the Identity property.
This code authenticates the user (logs in):
controller...() { ... if (User.Identity.IsAuthenticated) ... ... }
source share