Securing your ASP.NET Website

Slides:



Advertisements
Similar presentations
Forms Authentication, Users, Roles, Membership Ventsislav Popov Crossroad Ltd.
Advertisements

Forms Authority Database Store Username and Passwords: ASP.NET framework allows you to control access to pages, classes, or methods based on username and.
Members Only & Login Modules Members Only works with the Login module to provide password protection to Web pages and files. Login Groups may be created.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
1 Configuring Web services (Week 15, Monday 4/17/2006) © Abdou Illia, Spring 2006.
ASP.NET Security MacDonald Ch. 18 MIS 424 MIS 424 Professor Sandvig Professor Sandvig.
Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
Building ASP.NET Applications 2 Lecture 3,4 T. Ahlam Algharasi 4 th Level.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
CONFIGURING WINDOWS SERVER MIS 424 Professor Sandvig.
Microsoft Windows 2003 Server. Client/Server Environment Many client computers connect to a server.
Deployment of web Site. Preparing the web site for deployment you now have two versions of web site 1 -one running in the production environment 2-one.
Session 11: Security with ASP.NET
Forms Authentication, Users, Roles, Membership Svetlin Nakov Telerik Corporation
Chapter 13 – Advanced Topics Dr. Stephanos Mavromoustakos.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Copyright 2000 eMation SECURITY - Controlling Data Access with
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Securing a Microsoft ASP.NET Web Application.
Database-Driven Web Sites, Second Edition1 Chapter 5 WEB SERVERS.
FTP Server and FTP Commands By Nanda Ganesan, Ph.D. © Nanda Ganesan, All Rights Reserved.
Chapter 13 Users, Groups Profiles and Policies. Learning Objectives Understand Windows XP Professional user accounts Understand the different types of.
Module 5 Configuring Authentication. Module Overview Lesson 1: Understanding Classic SharePoint Authentication Providers Lesson 2: Understanding Federated.
1 CS 3870/CS 5870: Note 11 Authentication and Authorization Membership Provider.
Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
PROG Advanced Web Applications With.NET PROG Advanced Web Applications With.NET User Authentication & Authorization.
Module 11: Securing a Microsoft ASP.NET Web Application.
Slide 1 ASP Authentication There are basically three authentication modes Windows Passport Forms There are others through WCF You choose an authentication.
What is Web Site Administration Tool ? WAT Allow you to Configure Web Site With Simple Interface –Manage Users –Manage Roles –Manage Access Rules.
Role Management in.NET Shree Shalini Pusapati CS /17/20151.
MEMBERSHIP AND IDENTITY Active server pages (ASP.NET) 1 Chapter-4.
Implementing and Using the SIRWEB Interface Setup of the CGI script and web procfile Connecting to your database using HTML Retrieving data using the CGI.
1 CS 3870/CS 5870: Note 12 Authentication and Authorization Membership Provider.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Configuring and Deploying Web Applications Lesson 7.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
Security. Agenda ASP.NET security basics AuthenticationAuthorization Security principals Forms authentication Membership service Login controls Role Management.
Part 2.
Working with ASP.NET Controls What is ASP.NET Using server controls in your pages Allowing users to create their own accounts Creating a login page Letting.
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
SQL Database Management
Architecture Review 10/11/2004
Core ELN Training: Office Web Apps (OWA)
Authentication and Authorization
ASP.NET Programming with C# and SQL Server First Edition
Intro to WordPress (Using XAMPP)
Security In your webSite.
Unit 7 Learning Objectives
Authentication and Authorisation in ASP.Net
ASP .NET MVC Authorization Training Videos
Session Variables and Post Back
CARA 3.10 Major New Features
Security Basics and ASP.NET Support
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek
To Join the Teleconference
Multi-Factor Authentication (MFA)
What Is Sharepoint? Mohsen Ashkboos
Unit 27 - Web Server Scripting
The Application Lifecycle
Application Infrastructure
Welcome to FOCUS FOCUS website:
Introduction to .net Impersonation
Created by : Asst. Prof. Ashish Shah
Configuring Internet-related services
Role Management in .net Vinay Dhareshwar.
Inside a PMI Online Course
Security - Forms Authentication
MY NCBI (module 4.5).
Presentation transcript:

Securing your ASP.NET Website Chapter 16 Securing your ASP.NET Website

Objectives Important terminology you’ll encounter when dealing with security The ASP.NET application services that drive the security model of ASP.NET How you can let users sign up for an account for your site How users can reset their passwords or request new ones How you can manage the users and roles in your database at development time How you can present different content to different users based on their access rights in the system

Security Security aims to answer the following: Identity: Who are you? Authentication: How can you prove who you are? Authorization: What are you allowed to do here? Permissions: based on the username and roles. Authorization rules: rules for a resource that the user is trying to access ASP.NET 4.5.1 contains the following application services to implement security: Membership — Enables you to manage and work with user accounts in your system. Roles — Enables you to manage the roles to which your users can be assigned. Profile — Enables you to store user-specific data in a back-end database.

ASP.NET Security

ASP.NET Security For flexibility, services talk to a provider who then talks to the data store. Microsoft released the Universal Providers that work the same as the SQL Server providers, but can be used to target all editions of SQL Server, including SQL Server Compact and SQL Azure. You can change providers through configuration and not code. Each provider needs a data store to operate correctly. Ideally, you don’t deal with these providers directly. Under normal circumstances, the various providers are configured for your website at a central location. ASP.NET built-in login controls access the services directly.

ASP.NET Security If the providers are not installed (you should see System.Web.Providers.dll in you Bin folder), then you can installed them directl from Nu. Install-Package Microsoft.AspNet.Providers Drag a Login control into a page. The Login control has the following attributes:

ASP.NET Security DestinationURL: This is where you will go if authentication is successful. CreateUserText: This is the Text that is shown to the user so that they can create a new account CreateUserURL: The web page where the user will be created if they need to be.

ASP.NET Security Modify the Web.config to enable Forms authentication <system.web> <authentication mode="Forms" /> ... </system.web> Also, specify the database conntection string to store the provider’s data: <membership defaultProvider="DefaultMembershipProvider"> <providers> <add name="DefaultMembershipProvider" ... Other attributes here connectionStringName="PlanetWroxConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" .. Other attributes here /> </providers> </membership>

ASP.NET Security The Login Control is now configured to operate:

ASP.NET Security ASP.NET controls talk to the configured application service providers; a software layer that sits between the login controls and the SQL Server database that keeps track of the users. If the database from the connection string doesn’t exist, or it doesn’t contain the necessary tables, .NET executes a SQL script to prepare the database for you. New tables are: Memberships, Profiles, Roles, Applications,Users, UserInRoles

ASP.NET Security You can configure the forms timeout to allow the user to keep a cookie that allows them to reauthenticate. <authentication mode="Forms"> <forms timeout="1440" /> </authentication> This means that if the user checked off “Remember Me” they will not need to login again unless they exceed the timeout time without login in.

The Login Controls ASP.NET contains 7 login controls. Login Control LoginView Control LoginStatus Control LoginName Control CreteUserWizard Control PasswordRecovery Control ChangePassword Control

Login Control Login control enables the user to log in to the website. The control talks to the configured Membership provider through the application services to see if the username and password represent a valid user in the system. If the user is validated, a cookie is issued that is sent to the user’s browser. On future requests, the browser resubmits the cookie to the server so the system knows it’s still dealing with a valid user. <asp:Login ID="Login1" runat="server" />

Login Control Also has the following:

Login Control Authentication in .NET assumes that Login.aspx is the default login page. To change this, modify the forms tag in web.config. <authentication mode="Forms"> <forms loginUrl="~/Account/MyLoginPage.aspx" /> </authentication> The control supports styling if there needs to be any, and you can move the styling to CSS. After a user logs in, the event Logged fires. This is a good place to intercept a logged in user and transfer them to a page.

LoginView Control LoginView lets you display different data to different users. It is a template driven control.

LoginView Control You add markup to this control to provide messages in the templates. <asp:LoginView ID="LoginView1" runat="server"> <AnonymousTemplate> Hi there visitor. Would you be interested in signing up for an account? </AnonymousTemplate> <LoggedInTemplate> Hi there visitor and welcome back to PlanetWrox.com. </LoggedInTemplate> <RoleGroups> <asp:RoleGroup Roles="Managers"> <ContentTemplate> Hi there manager. You can proceed to the Management section. </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView>

LoginStatus Control LoginStatus control provides information about the current status of the user. It provides a Login link when the user is not authenticated and a Logout link when the user is already logged in. Text being displayed can be controlled by LoginText and LogoutText properties. LoginImageURL and LogoutImageURL can be used to display images instead. LogOutAction determines if the current page is refreshed or taken to another page as defined by LogoutPageUrl. This control raises the events LogginOut (right before loggin out) and LoggedOut (right after logging out).

LoginName Control Displays the logged in user. You can format with an existing string using a string format {0}. <asp:LoginName ID="LoginName1" runat="server" FormatString="Logged in as {0}" /> Example of a full implementation: <asp:LoginView ID="LoginView1" runat="server"> <AnonymousTemplate> <asp:Login ID="Login1" runat="server" CreateUserUrl="SignUp.aspx" DestinationPageUrl="~/Default.aspx" CreateUserText="Sign Up for a New Account at Planet Wrox"> </asp:Login> </AnonymousTemplate> <LoggedInTemplate> You are already logged in. </LoggedInTemplate> </asp:LoginView>

CreateUserWizard Control Helps create a user through the respective provider. Has properties that can change the Text properties, such as CancelButtonText, CompleteSucessText, UserNameLabelText and CreateUserButtonText.

CreateUserWizard Control Other properties

PasswordRecovery Control Enables users to retrieve their existing passwords or gets a new auto- generated password to be sent to the email address for the user. Properties: GeneralFailureText: Shows when password cannot be recovered. SuccessText: Shows when password is received. ButtonType, ButtonText, ButtonImageUrl:Change the look and behavior of the action buttons of the control. SuccessPageUrl: Goes to another site if the recovery succeeds.

ChangePassword Control Enables logged in and existing users to change their password. <asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server"> <h1>My Profile</h1> <p>The My Profile page allows you to make changes to your personal profile. For now, all you can do is change your password below.</p> <asp:ChangePassword ID="ChangePassword1" runat="server"></asp:ChangePassword>

Changing a password By default, your passwords are stored in a hashed format in the database, which means they cannot be retrieved. Hashing is an irreversible process that creates a unique fingerprint of your data. When you log in, the password you enter is also hashed and then the two hashes are compared to see if you are allowed to enter. Because the original password cannot be retrieved, the PasswordRecovery control generates a new password for you. It then sends this password to the e-mail address that is associated with the username you entered.

Configuring the Security of your Web App Inside the web.config, you can change the attributes of your membership provider. <membership defaultProvider="DefaultMembershipProvider"> <providers> <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10“ applicationName="/" /> </providers> </membership>

Configuring the Security of your Web App

Configuring the Security of your Web App

Configuring the Security of your Web App

Configuring the Security of your Web App The CreateUserWizard uses the configured Membership provider under the hood to validate the data and create the user. The provider in turn consults the Web.config file for the configuration information such as the minimum password length. When you try to create the user, the provider enforces the rules set in Web.config and cancels the user creation process as soon as one of the rules is not fulfilled.

Role Manager The Role Manager is available to manager security through Roles. Roles is a functional grouping of the users so that you can apply security rights to the role instead of the user. Role Management has to be enabled through the DefaultRoleProvider. <roleManager defaultProvider="DefaultRoleProvider"> <providers> <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" applicationName="/" /> </providers> </roleManager>

Role Manager The Role Manager is not enabled by default, and to enable it, you need to add an enabled="true“ attribute to the <roleManager /> element. With the Membership and Role Manager providers configured and the database created, it’s time to manage the users and roles in your system. You have a few ways to accomplish that: Using the Web Site Administration Tool, generally referred to as the WSAT Using IIS (the Windows web server) on recent Windows editions (you see more about this in Chapter 19) Programmatically, using the Role Manager API (application programming interface)

Managing Users with WSAT The Web Site Administration Tool is used for the following tasks: Managing users Managing roles Managing access rules — for example, to determine what user can access which files and folders Configuring application, mail, and debug settings Taking the site offline so users can’t request any pages and get a friendly error message instead It is only available from your local machine to initially setup users, but its not usable for a production environment.

Managing Users with WSAT The WSAT:

Managing Users with WSAT Managing Users, Roles and Access Rules

Configuring Web Applications to Work with Roles The Access Rules allow you to configure the users or roles that have (or do not) have access to folders or files. The security settings are stored in web.config. For example, limit access to the “Management” folder <location path="Management"> <system.web> <authorization> <allow roles="Managers" /> <deny users="*" /> </authorization> </system.web> </location>

Configuring Web Applications to Work with Roles The security model works inside out, it starts by scanning the Web.config file (if present) in the folder that contains the requested page and then works its way up hierarchically to the root. If it doesn’t find the file there or it doesn’t contain settings that block or grant access, it goes up in the folder hierarchy searching for configuration files with authorization elements. The “?” can be used to denote unauthenticated users. <location path="Reviews"> <system.web> <authorization> <deny users="?" /> </authorization> </system.web> </location>

Programmatically Checking Roles LoginView control is used to change the content a user is allowed to see at run time, but sometimes this needs to be done programmatically. You can use IsInRole from the User object if (User.IsInRole("Managers")) { // This code runs for Managers only } Or you can use the Roles objects. if (Roles.IsUserInRole("Managers")) The IsUserInRole method returns a boolean that indicates whether the current user is a manager.

Summary In this chapter we covered: Learned important terminology you’ll encounter when dealing with security Learned the ASP.NET application services that drive the security model of ASP.NET Reviewed how you can let users sign up for an account for your site Reviewed How users can reset their passwords or request new ones Learned How you can manage the users and roles in your database at development time Learned how you can present different content to different users based on their access rights in the system