MVC works just like ASP.NET.
If you use Form Authentication, many of these questions will be answered.
In your web configuration, find the line that says authentication="Windows" and then change it to Forms
<authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" /> </authentication>
MVC 3 will actually provide you with an Account / LogOn route as part of the MVC 3 template project (check your models and see if you have one call to AccountModel ).
Then you simply add Authorization to block all users from your site:
<authorization> <deny users="?"/> </authorization>
by default, this will send any person who comes to your site to your login.
So, after you have verified that credential authorization is correct, you install AuthCookie just like ASP.NET:
FormsAuthentication.SetAuthCookie(userName, false);
Form it, you can redirect to wherever you want.
redirect back to where you came from:
FormsAuthentication.RedirectFromLoginPage(userName, false);
Not forgetting another useful instruction:
FormsAuthentication.SignOut();
Without authentication, the site will not allow you to access anywhere until you log in, so CSS will stop working.
The places I added to make sure this does not happen are as follows:
<location path="Content"> <system.web> <authorization> <allow users="?"/> </authorization> </system.web> </location> <location path="Scripts"> <system.web> <authorization> <allow users="?"/> </authorization> </system.web> </location>