MVC Authorisation
MVC Authorisation
Membership,
Authorization, and Security
By
Amareswar Rao
2
Authorize Attribute
3
Secure Application With
ASP.NET Webforms
A common means of securing an application with Web
Forms is to use URL authorization.
4
AuthorizeAttribute
If you don't specify any roles or users, the current user must
simply be authenticated
Install-Package Wrox.ProMvc4.Security.Authorize
5
AuthorizeAttribute with
Forms Authentication
IPrincipal user = httpContext.User; if (!
user.Identity.IsAuthenticated) { return false; }
6
Windows Authentication
IIS 7
IIS 8
IIS Express
7
Forms Authentication
[Authorize] public ActionResult Buy(int id)
RegisterGlobalFilters(GlobalFilterCollection filters)
{ filters.Add(new
System.Web.Mvc.AuthorizeAttribute());
filters.Add(new HandleErrorAttribute()); }
8
Web Forms and static resources map to file
paths and can be secured using the
authorization element in your web.config
9
Authorize Attribute - Role
Membership
[Authorize(Roles="Administrator")] public class
StoreManagerController : Controller
[Authorize(Roles="UsersNamedScott", Users="Jon,Phil,Brad")]
public class TopSecretController:Controller
10
OAuth & OpenID
OAuth and OpenID are open standards
for authorization. These protocols allow
your users to log in to your site using
their existing accounts on other trusted
sites (called providers ), such as Google,
Twitter, Microsoft, and others.
11
App_Start\AuthConfig.cs
12
13
Require SSL for Login
14