160 likes | 474 Views
ASP.NET Security. Securing your ASP.NET web site. General security terms. Identity: Who are you? Examples: user name, CPR, email address, etc. Authentication: How can you prove who you are? Examples: Password Authorization: What are you allowed to do? Permission rules for the user
E N D
ASP.NET Security Securing your ASP.NET web site ASP.NET Security
General security terms • Identity: Who are you? • Examples: user name, CPR, email address, etc. • Authentication: How can you prove who you are? • Examples: Password • Authorization: What are you allowed to do? • Permission rules for the user • Authorization rules for the resources • Roles (security groups) • A user is assigned to a number of roles • Members of a role has access to certain resources ASP.NET Security
ASP.NET Application Services • Membership • Manage and use ”user accounts” • Roles • Manage and use ”roles” • Profile • Store user-specific data in database • Figure from • http://imar.spaanjaars.com/404/using-the-microsoft-access-providers-to-replace-the-built-in-sql-server-providers ASP.NET Security
Login Controls • Login • Form used for login (username + password) • LoginView • Display different data to different users • AnonymousTemplate • LoggedInTemplate • RoleGroups • LoginStatus • Show whether the current user is logged in or not • LoginName • Show the name of the current user • Example • Aspnet/security/logincontrol ASP.NET Security
Login controls, continued • CreateUserWizard • Form to create a new user • PasswordRecovery • Form to recover a lost password • Send by email • ChangePassword • Form to change password ASP.NET Security
Role management • Users are assigned to one or more roles • Each role has access to a number of resources • Like files and folders ASP.NET Security
WSATWeb Site Administration Tool • WSAT is used for • Managing users • Managing roles • Managing access rules • Etc. • Information is stored in a database • ASPNETDB.MDF in the project’s App_Data folder • Visual Studio • ”Website” menu -> ASP.NET Configuration ASP.NET Security
Access rules • Access rules are set in web.config • Enable the roles manager • <roleManager enabled="true" /> • Protect the files in a specific folder <location path="secrets"> <system.web> <authorization> <allow roles="teacher"/> <deny users="*"/> </authorization> </system.web> </location> • If no rule is satisfied, access is granted! • That’s why <deny users="*"/> is necessary • Dis-allowing anonymous users • <deny users=”?” /> ASP.NET Security
Programmatically checking roles • Checking roles in the code behind (C#) • If (User.IsInRole(someRole)) … • Roles manager not needed • If (Roles.IsUserInRole(someRole)… • Roles manager needed • Example: logincontrol/default.aspx.cs ASP.NET Security
Further readings, etc. • Imar SpaanjaarsBeginning ASP.NET 4 in C# and VB, Wrox 2010 • Chapter 16 Security in your ASP.NET 4 web site, page 579-618 • Bill EvjenProfessional ASP.NET 4 in C# and VB, Wrox 2010 • Chapter 20 Security, page 805-833 • George ShepherdMicrosoft ASP.NET 4 Step-by-step, Microsoft Press 2010 • Chapter 9 Logging In, page 181-206 • Joe StagnerLogin Controls (video) • http://www.asp.net/general/videos/login-controls • Joe Stagner Security Videos • http://www.asp.net/security/videos ASP.NET Security