ASP.NET Web API Security Essentials
()
About this ebook
Read more from Gunasundaram Rajesh
CORS Essentials Rating: 0 out of 5 stars0 ratingsLearning Angular for .NET Developers Rating: 0 out of 5 stars0 ratings
Related to ASP.NET Web API Security Essentials
Related ebooks
Jakarta EE for Java Developers: Build Cloud-Native and Enterprise Applications Using a High-Performance Enterprise Java Platform Rating: 0 out of 5 stars0 ratingsLearning ASP.NET Core MVC Programming Rating: 5 out of 5 stars5/5Mockito for Spring Rating: 0 out of 5 stars0 ratingsASP.NET Core 3 and React: Hands-On full stack web development using ASP.NET Core, React, and TypeScript 3 Rating: 0 out of 5 stars0 ratingsImplementing C# 11 and .NET 7.0: Learn how to build cross-platform apps with .NET Core (English Edition) Rating: 0 out of 5 stars0 ratingsThe PHP Workshop: Learn to build interactive applications and kickstart your career as a web developer Rating: 0 out of 5 stars0 ratingsASP.NET Core for Jobseekers: Build Career in Designing Cross-Platform Web Applications Using Razor and Entity Framework Core Rating: 0 out of 5 stars0 ratingsUnlock PHP 8: From Basic to Advanced: The next-level PHP 8 guide for dynamic web development (English Edition) Rating: 0 out of 5 stars0 ratingsHands-On Network Programming with C# and .NET Core: Build robust network applications with C# and .NET Core Rating: 0 out of 5 stars0 ratingsSpring Microservices Rating: 0 out of 5 stars0 ratingsIntroduction to PHP Web Services: PHP, JavaScript, MySQL, SOAP, RESTful, JSON, XML, WSDL Rating: 0 out of 5 stars0 ratingsBuilding a Web App with Blazor and ASP .Net Core: Create a Single Page App with Blazor Server and Entity Framework Core Rating: 0 out of 5 stars0 ratingsCode with Java 21: A practical approach for building robust and efficient applications (English Edition) Rating: 0 out of 5 stars0 ratingsMastering PHP 7 Rating: 1 out of 5 stars1/5Python for Google App Engine Rating: 0 out of 5 stars0 ratingsBuilding Microservices with .NET Core Rating: 1 out of 5 stars1/5Ultimate Web Authentication Handbook Rating: 0 out of 5 stars0 ratings.NET Design Patterns Rating: 3 out of 5 stars3/5Ian Talks JavaScript Libraries and Frameworks A-Z: WebDevAtoZ, #4 Rating: 0 out of 5 stars0 ratings50 C# Concepts Every Developer Should Know Rating: 0 out of 5 stars0 ratingsNginx Essentials Rating: 0 out of 5 stars0 ratings.NET 7 for Jobseekers: Elevate your coding journey with .NET 7 (English Edition) Rating: 0 out of 5 stars0 ratingsDeploying Node.js Rating: 5 out of 5 stars5/5Test-Driven Java Development Rating: 0 out of 5 stars0 ratingsEnterprise Applications with C# and .NET: Develop robust, secure, and scalable applications using .NET and C# (English Edition) Rating: 0 out of 5 stars0 ratingsReact and React Native: Build cross-platform JavaScript and TypeScript apps for the web, desktop, and mobile Rating: 5 out of 5 stars5/5Vue.js for Jobseekers: A complete guide to learning Vue.js, building projects, and getting hired (English Edition) Rating: 0 out of 5 stars0 ratings
Internet & Web For You
Audio Manual for Podcasts: Learn Digital Audio Basics and Improve the Sound of your Podcasts: Stefano Tumiati, #4 Rating: 0 out of 5 stars0 ratingsMastering UX Design with Effective Prototyping: Turn your ideas into reality with UX prototyping (English Edition) Rating: 0 out of 5 stars0 ratingsLearn SAP BI in 24 Hours Rating: 3 out of 5 stars3/5Digital Disconnect: How Capitalism is Turning the Internet Against Democracy Rating: 4 out of 5 stars4/5The Book Blogger Platform Rating: 3 out of 5 stars3/5Moderation: LISTED FOR THE WOMEN'S PRIZE FOR FICTION 2026 Rating: 2 out of 5 stars2/5SEO Mastery: A Complete Guide to Search Engine Optimization in 2025 Rating: 0 out of 5 stars0 ratingsCreative Culture: Human-Centered Interaction, Design, & Inspiration Rating: 4 out of 5 stars4/5The Logo Brainstorm Book: A Comprehensive Guide for Exploring Design Directions Rating: 4 out of 5 stars4/5Allow Me to Introduce Myself: 'You will not be able to put this down' Glamour Rating: 4 out of 5 stars4/5Every Page is Page One Rating: 3 out of 5 stars3/5Work Smarter with LinkedIn Rating: 0 out of 5 stars0 ratingsProBlogger: Secrets for Blogging Your Way to a Six-Figure Income Rating: 4 out of 5 stars4/5Hack Computer System For Noobee Rating: 1 out of 5 stars1/5How to Grow on Threads in 2026 Rating: 0 out of 5 stars0 ratingsThe Designer's Web Handbook: What You Need to Know to Create for the Web Rating: 0 out of 5 stars0 ratingsVideo Podcasting Made Easy Rating: 0 out of 5 stars0 ratingsThe House Mate: A gripping psychological thriller you won't be able to put down Rating: 3 out of 5 stars3/5Canva From Beginner To Pro: Step By Step Guide To Create Professional Designs For Graphics, Social Media, Presentations, Videos Rating: 0 out of 5 stars0 ratingsDesign for Real Life Rating: 4 out of 5 stars4/5No One Wants To Buy Your Stuff Rating: 0 out of 5 stars0 ratingsHow to Make Money with Faceless YouTube using AI Rating: 0 out of 5 stars0 ratingsWeb Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5JavaScript Made Easy: A Beginner's Practical Guide to Coding Interactive Web Pages Rating: 0 out of 5 stars0 ratingsScammed: Learn from the Biggest Consumer and Money Frauds How Not to Be a Victim Rating: 0 out of 5 stars0 ratingsThe Art of Email Security: Putting Cybersecurity In Simple Terms Rating: 2 out of 5 stars2/5C# for Beginners: Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsWordPress For Dummies Rating: 0 out of 5 stars0 ratingsPlanet High School Rating: 5 out of 5 stars5/5Metasploit Bootcamp Rating: 5 out of 5 stars5/5
Reviews for ASP.NET Web API Security Essentials
0 ratings0 reviews
Book preview
ASP.NET Web API Security Essentials - Gunasundaram Rajesh
Table of Contents
ASP.NET Web API Security Essentials
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Setting up a Browser Client
ASP.NET Web API security architecture
Setting up your browser client
Implementing Web API lookup service
Adding a model
Adding a controller
Consuming the Web API using JavaScript and jQuery
Getting a list of contacts
Getting a contact by ID
Running the application
Authentication and authorization
Authentication
Authorization
Implementing authentication in HTTP message handlers
Setting the principal
Using the [Authorize] attribute
Global authorization filter
Controller level authorization filter
Action level authorization filter
Custom authorization filters
Authorization inside a controller action
Summary
2. Enabling SSL for ASP.NET Web API
Enforcing SSL in a Web API controller
Using client certificates in Web API
Creating an SSL Client Certificate
Configuring IIS to accept client certificates
Verifying Client Certificates in Web API
Summary
3. Integrating ASP.NET Identity System with Web API
Creating an Empty Web API Application
Installing the ASP.NET Identity NuGet packages
Setting up ASP.NET Identity 2.1
ASP.NET Identity
Defining Web API Controllers and methods
Testing the application
Summary
4. Securing Web API Using OAuth2
Hosting OWIN in IIS and adding Web API to the OWIN pipeline
Individual User Account authentication flow
Sending an unauthorized request
Get an access token
Send an authenticated request
Summary
5. Enabling Basic Authentication using Authentication Filter in Web API
Basic authentication with IIS
Basic authentication with custom membership
Basic authentication using an authentication filter
Setting an authentication filter
Action-level authentication filter
Controller-level authentication filter
Global-level authentication filter
Implementing a Web API authentication filter
Setting an error result
Combining authentication filters with host-level authentication
Summary
6. Securing a Web API using Forms and Windows Authentication
Working of Forms authentication
Implementing Forms authentication in Web API
What is Integrated Windows Authentication?
Advantages and disadvantages of using the Integrated Windows Authentication mechanism
Configuring Windows Authentication
Difference between Basic Authentication and Windows authentication
Enabling Windows authentication in Katana
Summary
7. Using External Authentication Services with ASP.NET Web API
Using OWIN external authentication services
Creating an ASP.NET MVC Application
Implementing Facebook authentication
Implementing Twitter authentication
Implementing Google authentication
Implementing Microsoft authentication
Discussing authentication
Summary
8. Avoiding Cross-Site Request Forgery Attacks in Web API
What is a CSRF attack?
Anti-forgery tokens using HTML Form or Razor View
How does an Anti-forgery token work?
Anti-forgery tokens using AJAX
Summary
9. Enabling Cross-Origin Resource Sharing (CORS) in ASP.NET Web API
What is CORS?
How CORS works
Setting the allowed origins
Setting the allowed HTTP methods
Setting the allowed request headers
Setting the allowed response headers
Passing credentials in cross-origin requests
Enabling CORS at various scope
Enable at action level
Enable at controller level
Enable CORS globally
Summary
Index
ASP.NET Web API Security Essentials
ASP.NET Web API Security Essentials
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2015
Production reference: 1241115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-221-0
www.packtpub.com
Credits
Author
Rajesh Gunasundaram
Reviewer
Anuraj Parameswaran
Commissioning Editor
Amarabha Banerjee
Acquisition Editor
Prachi Bisht
Content Development Editor
Anish Dhurat
Technical Editor
Danish Shaikh
Copy Editor
Vibha Shukla
Project Coordinator
Harshal Ved
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Production Coordinator
Nilesh Mohite
Cover Work
Nilesh Mohite
About the Author
Rajesh Gunasundaram is a software architect, technical writer and blogger. He has over 13 years of experience in the IT industry, with more than 10 years using Microsoft's .NET and 2 years of using BizTalk Server, and a year of iOS application development.
Rajesh is a founder and an editor of technical blogs: www.programmerguide.net and www.ioscorner.com. You can find many of his technical writings on .NET and iOS.
Rajesh holds a master's degree in computer application and began his career as a software engineer in the year 2002. He has worked on client premises located in various countries, such as the UK, Belarus, and Norway. He is also experienced in developing mobile applications for iPhone and iPad.
His technical strengths include Objective-C, C#, ASP.NET MVC, Web API, WCF, .Net Framework 4.5, AngularJS, BizTalk, SQL Server, REST, SOA, design patterns, and software architecture.
Acknowledgments
I am greatly thankful to my beloved and wonderful friend Ahila Dhayalan, who has constantly encouraged and motivated me while writing this book. She put me back on track whenever I deviated from my schedule of submitting the chapters. Without her support and encouragement, this book wouldn't have been possible.
I am also thankful to the entire team at Packt Publishing for providing me the opportunity to author this book.
Thanks to Prachi Bisht for having confidence in me and giving me the opportunity to write this book.
Thanks to Ajinkya Paranjape for having high regard for me and providing invaluable assistance.
Thanks to Anish Dhurat for guiding and helping me to shape the content of the book.
Thanks to Danish Shaikh for verifying the technical content and bringing it to a good shape.
About the Reviewer
Anuraj Parameswaran works as an architect in Orion India Systems Pvt. Ltd., Kochi. He has extensive experience of more than ten years in working on different technologies, mostly in the Microsoft space. He has been working on the .NET platform since its early days. He leads the technology and innovation team at Orion. He is a cofounder of MobiThoughts, a mobile application development company. His focus areas are data analytics, architecture, and Cloud computing.
He writes about technology in his popular blog at http://www.dotnetthoughts.net/. He is a K-MUG Community Council member and an active volunteer in Microsoft Technology Community.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
Support files, eBooks, discount offers, and morehttps://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to
