SlideShare une entreprise Scribd logo
1  sur  18
• Authentication and Authorization
• Forms Authentication
   • Web.config Settings
   • Authorization Rules
   • Controlling access to specific directories
   • Controlling access to specific files
   • Controlling access to specific users
   • Persistent Cookies
• Windows Authentication
   • Web.config Settings
   • A windows authentication test
Authentication: This is the process of determining a
user’s identity and forcing users to prove they are who
they claim to be. Usually, this involves entering
credentials (typically a user name and password) into
some sort of login page or window. These credentials
are then authenticated against the Windows user
accounts on a computer, a list of users in a file, or a
back-end database.

Authorization: Once a user is authenticated,
authorization is the process of determining whether
that user has sufficient permissions to perform a given
action (such as viewing a page or retrieving
information from a database).
Forms authentication: ASP.NET is in charge of
authenticating users, tracking them, and authorizing
every. Forms authentication is the best and most flexible
way to run a subscription site or e-commerce store.

Windows authentication: With Windows authentication,
the web server forces every user to log in as a Windows
user. This system requires that all users have Windows
user accounts on the server. This scenario is poorly
suited for a public web application but is often ideal with
an intranet or company-specific site designed to provide
resources for a limited set of users.
To implement forms-based security, you need to follow
three steps:

1. Set the authentication mode to forms authentication
in the web.config file. (If you prefer a graphical tool,
you can use the WAT during development or IIS
Manager after deployment.)

2. Restrict anonymous users from a specific page or
directory in your application.

3. Create the login page.
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="MyAppCookie"
loginUrl="~/Login.aspx"
protection="All"
timeout="30" path="/" />
</authentication>
...
</system.web>
</configuration>
<configuration>
<system.web>
….
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>

<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
...
</system.web>
</configuration>
Leave the default <authorization> settings in the
normal parent directory, and add a web.config file that
specifies stricter settings in the secured directory.
This web.config simply needs to deny anonymous users
(all other settings and configuration sections can be
omitted).
<!-- This web.config file is in a subfolder. -->
<configuration>
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>
<authorization>
<allow users="*" />
</authorization>
</system.web>

<location path="AnotherSecuredPage.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
The <allow> and <deny> rules don’t need to use the
asterisk or question mark wildcards. Instead, they can
specifically identify a user name or a list of comma-
separated user names.
<authorization>
<deny users="?" />
<deny users="matthew,sarah" />
<deny users="john" />
<allow users="*" />
</authorization>
ASP.NET provides a special FormsAuthentication class
in the System.Web.Security namespace, which provides
static methods that help manage the process

public partial class Login : System.Web.UI.Page
{
protected void cmdLogin_Click(Object sender, EventArgs e)
{
if (txtPassword.Text.ToLower() == "secret")
{
FormsAuthentication.RedirectFromLoginPage(txtName.Text, false);
}
else
{
lblStatus.Text = "Try again.";
}
}
}
Once the user is logged in, you can retrieve the identity
through the built-in User property, as shown here:
protected void Page_Load(Object sender, EventArgs e)
{
lblMessage.Text = "You have reached the secured page, ";
lblMessage.Text += User.Identity.Name + ".";
}
You can access the User object in your code because it’s a
property of the current Page object. It has one property and
one method :
1. The Identity property lets you retrieve the name of the
    logged-in user and the type of authentication that was
    used.
2. • The IsInRole() method lets you determine whether a
    user is a member of a given role
A persistent authentication cookie remains on the
user’s hard drive and keeps the user signed in for
hours, days, or weeks—even if the user closes and
reopens the browser.

If you want to allow the user to create a persistent
cookie, you should make it optional, because the user
may want to access your site from a public or shared
computer. Generally, sites that use this technique
include a check box with text such as Keep Me
Logged In.
With Windows authentication, the web server takes care of the
authentication process. When you use Windows authentication,
you force users to log into IIS before they’re allowed to access
secure content in your website.

The user login information can be transmitted in several ways
but the end result is that the user is authenticated using a local
Windows account.

To implement Windows-based security with known users, you
need to follow three steps:

1. Set the authentication mode to Windows authentication in the
web.config file.
2. Disable anonymous access for a directory by using an
authorization rule.
3. Configure the Windows user accounts on your web server (if
they aren’t already present).
<configuration>
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?" />
<allow roles=".SalesAdministrator,.SalesStaff" />
<deny users=".matthew" />
</authorization>
...
</system.web>
</configuration>
protected void Page_Load(Object sender, EventArgs e)
{
if (User.IsInRole(@"MyDomainNameSalesAdministrators"))
{
}
else
{
Response.Redirect("Default.aspx");
}
if (User.IsInRole(@"BUILTINAdministrators"))
{
// (Code goes here.)
}

}
Chapter 19

Contenu connexe

En vedette

En vedette (20)

Bread board
Bread boardBread board
Bread board
 
Breadboard
BreadboardBreadboard
Breadboard
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Intro To ECAT
Intro To ECATIntro To ECAT
Intro To ECAT
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
CSS3 notes
CSS3 notesCSS3 notes
CSS3 notes
 
CSS
CSSCSS
CSS
 
HTML5 &CSS: Chapter 08
HTML5 &CSS: Chapter 08HTML5 &CSS: Chapter 08
HTML5 &CSS: Chapter 08
 
HTML & CSS: Chapter 07
HTML & CSS: Chapter 07HTML & CSS: Chapter 07
HTML & CSS: Chapter 07
 
Html and CSS: Chapter 02
Html and CSS: Chapter 02Html and CSS: Chapter 02
Html and CSS: Chapter 02
 
HTML & CSS: Chapter 03
HTML & CSS: Chapter 03HTML & CSS: Chapter 03
HTML & CSS: Chapter 03
 
HTML: Chapter 01
HTML: Chapter 01HTML: Chapter 01
HTML: Chapter 01
 
HTML & CSS: Chapter 06
HTML & CSS: Chapter 06HTML & CSS: Chapter 06
HTML & CSS: Chapter 06
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
 
HTML & CSS: Chapter 04
HTML & CSS: Chapter 04HTML & CSS: Chapter 04
HTML & CSS: Chapter 04
 
Unit 6, Lesson 3 - Vectors
Unit 6, Lesson 3 - VectorsUnit 6, Lesson 3 - Vectors
Unit 6, Lesson 3 - Vectors
 
Basic css
Basic cssBasic css
Basic css
 
Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS Properties
 
Vernier caliper
Vernier caliperVernier caliper
Vernier caliper
 
Spline Interpolation
Spline InterpolationSpline Interpolation
Spline Interpolation
 

Similaire à Chapter 19

08 asp.net session11
08 asp.net session1108 asp.net session11
08 asp.net session11
Mani Chaubey
 
08 asp.net session11
08 asp.net session1108 asp.net session11
08 asp.net session11
Niit Care
 
Authorization in asp
Authorization in aspAuthorization in asp
Authorization in asp
OPENLANE
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
Neeraj Mathur
 
Authentication
AuthenticationAuthentication
Authentication
soon
 

Similaire à Chapter 19 (20)

Security asp.net application
Security asp.net applicationSecurity asp.net application
Security asp.net application
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 
08 asp.net session11
08 asp.net session1108 asp.net session11
08 asp.net session11
 
Forms authentication
Forms authenticationForms authentication
Forms authentication
 
08 asp.net session11
08 asp.net session1108 asp.net session11
08 asp.net session11
 
08 asp.net session11
08 asp.net session1108 asp.net session11
08 asp.net session11
 
Authorization in asp
Authorization in aspAuthorization in asp
Authorization in asp
 
Introduction Yii Framework
Introduction Yii FrameworkIntroduction Yii Framework
Introduction Yii Framework
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
 
SCWCD : Secure web
SCWCD : Secure webSCWCD : Secure web
SCWCD : Secure web
 
SCWCD : Secure web : CHAP : 7
SCWCD : Secure web : CHAP : 7SCWCD : Secure web : CHAP : 7
SCWCD : Secure web : CHAP : 7
 
James Allardice - "Building a better login with the credential management API"
James Allardice - "Building a better login with the credential management API"James Allardice - "Building a better login with the credential management API"
James Allardice - "Building a better login with the credential management API"
 
Ekran system functions v. 5.0
Ekran system functions v. 5.0Ekran system functions v. 5.0
Ekran system functions v. 5.0
 
Java Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityJava Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application Security
 
Windows Small Business Server 2011 Nasıl Kullanılır
Windows Small Business Server 2011 Nasıl KullanılırWindows Small Business Server 2011 Nasıl Kullanılır
Windows Small Business Server 2011 Nasıl Kullanılır
 
SBS 2011 Kullanimi
SBS 2011 KullanimiSBS 2011 Kullanimi
SBS 2011 Kullanimi
 
Authentication
AuthenticationAuthentication
Authentication
 
Introduccion a la seguridad Windows 7
Introduccion a la seguridad Windows 7Introduccion a la seguridad Windows 7
Introduccion a la seguridad Windows 7
 
Spring4 security
Spring4 securitySpring4 security
Spring4 security
 
Introduction to Azure AD and Azure AD B2C
Introduction to Azure AD and Azure AD B2CIntroduction to Azure AD and Azure AD B2C
Introduction to Azure AD and Azure AD B2C
 

Plus de application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Assignment
AssignmentAssignment
Assignment
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
C # test paper
C # test paperC # test paper
C # test paper
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 

Chapter 19

  • 1. • Authentication and Authorization • Forms Authentication • Web.config Settings • Authorization Rules • Controlling access to specific directories • Controlling access to specific files • Controlling access to specific users • Persistent Cookies • Windows Authentication • Web.config Settings • A windows authentication test
  • 2. Authentication: This is the process of determining a user’s identity and forcing users to prove they are who they claim to be. Usually, this involves entering credentials (typically a user name and password) into some sort of login page or window. These credentials are then authenticated against the Windows user accounts on a computer, a list of users in a file, or a back-end database. Authorization: Once a user is authenticated, authorization is the process of determining whether that user has sufficient permissions to perform a given action (such as viewing a page or retrieving information from a database).
  • 3. Forms authentication: ASP.NET is in charge of authenticating users, tracking them, and authorizing every. Forms authentication is the best and most flexible way to run a subscription site or e-commerce store. Windows authentication: With Windows authentication, the web server forces every user to log in as a Windows user. This system requires that all users have Windows user accounts on the server. This scenario is poorly suited for a public web application but is often ideal with an intranet or company-specific site designed to provide resources for a limited set of users.
  • 4. To implement forms-based security, you need to follow three steps: 1. Set the authentication mode to forms authentication in the web.config file. (If you prefer a graphical tool, you can use the WAT during development or IIS Manager after deployment.) 2. Restrict anonymous users from a specific page or directory in your application. 3. Create the login page.
  • 6.
  • 7. <configuration> <system.web> …. <authentication mode="Forms"> <forms loginUrl="~/Login.aspx" /> </authentication> <authorization> <deny users="?" /> <allow users="*" /> </authorization> ... </system.web> </configuration>
  • 8. Leave the default <authorization> settings in the normal parent directory, and add a web.config file that specifies stricter settings in the secured directory. This web.config simply needs to deny anonymous users (all other settings and configuration sections can be omitted). <!-- This web.config file is in a subfolder. --> <configuration> <system.web> <authorization> <deny users="?" /> </authorization> </system.web> </configuration>
  • 9. <configuration> <system.web> <authentication mode="Forms"> <forms loginUrl="~/Login.aspx" /> </authentication> <authorization> <allow users="*" /> </authorization> </system.web> <location path="AnotherSecuredPage.aspx"> <system.web> <authorization> <deny users="?" /> </authorization> </system.web> </location> </configuration>
  • 10. The <allow> and <deny> rules don’t need to use the asterisk or question mark wildcards. Instead, they can specifically identify a user name or a list of comma- separated user names. <authorization> <deny users="?" /> <deny users="matthew,sarah" /> <deny users="john" /> <allow users="*" /> </authorization>
  • 11. ASP.NET provides a special FormsAuthentication class in the System.Web.Security namespace, which provides static methods that help manage the process public partial class Login : System.Web.UI.Page { protected void cmdLogin_Click(Object sender, EventArgs e) { if (txtPassword.Text.ToLower() == "secret") { FormsAuthentication.RedirectFromLoginPage(txtName.Text, false); } else { lblStatus.Text = "Try again."; } } }
  • 12.
  • 13. Once the user is logged in, you can retrieve the identity through the built-in User property, as shown here: protected void Page_Load(Object sender, EventArgs e) { lblMessage.Text = "You have reached the secured page, "; lblMessage.Text += User.Identity.Name + "."; } You can access the User object in your code because it’s a property of the current Page object. It has one property and one method : 1. The Identity property lets you retrieve the name of the logged-in user and the type of authentication that was used. 2. • The IsInRole() method lets you determine whether a user is a member of a given role
  • 14. A persistent authentication cookie remains on the user’s hard drive and keeps the user signed in for hours, days, or weeks—even if the user closes and reopens the browser. If you want to allow the user to create a persistent cookie, you should make it optional, because the user may want to access your site from a public or shared computer. Generally, sites that use this technique include a check box with text such as Keep Me Logged In.
  • 15. With Windows authentication, the web server takes care of the authentication process. When you use Windows authentication, you force users to log into IIS before they’re allowed to access secure content in your website. The user login information can be transmitted in several ways but the end result is that the user is authenticated using a local Windows account. To implement Windows-based security with known users, you need to follow three steps: 1. Set the authentication mode to Windows authentication in the web.config file. 2. Disable anonymous access for a directory by using an authorization rule. 3. Configure the Windows user accounts on your web server (if they aren’t already present).
  • 16. <configuration> <system.web> <authentication mode="Windows" /> <authorization> <deny users="?" /> <allow roles=".SalesAdministrator,.SalesStaff" /> <deny users=".matthew" /> </authorization> ... </system.web> </configuration>
  • 17. protected void Page_Load(Object sender, EventArgs e) { if (User.IsInRole(@"MyDomainNameSalesAdministrators")) { } else { Response.Redirect("Default.aspx"); } if (User.IsInRole(@"BUILTINAdministrators")) { // (Code goes here.) } }