public IMembershipService MembershipService { get; set; }
protected override void Initialize(RequestContext requestContext)
{
if (FormsService == null) { FormsService = new
FormsAuthenticationService(); }
if (MembershipService == null) { MembershipService = new
AccountMembershipService(); }
base.Initialize(requestContext);
}
The IMembershipService interface and AccountMembershipService implementation are in the AccountModels file.
Of course you can check whether the current identity is authorized without having to directly use the Membership.Provider object, by using the AuthorizeAttribute attribute.
[Authorize]
public ActionResult About()
{
return View();
}
Adding this attribute to the action method declaration will make the MVC runtime check whether the identity is authenticated. If the identity is not authenticated, the runtime will throw a SecurityException exception.