-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
ASP.NET Web API Security Essentials
By :
With the release of ASP.NET Web API 2.0, it is best practice to use an authentication filter for basic authentication rather than using an HTTP module. Follow the given steps to implement basic authentication using an authentication filter:
Create New Project from the Start page in Visual Studio.
Select Visual C# Installed Template named Web.
Select ASP.NET Web Application in the center pane.
Name the project Chapter05.BasicAuthentication and click OK:

Fig 3 – We have named the ASP.NET Web Application as "Chapter05.BasicAuthentication"
Select the MVC template in the New ASP.NET Project dialog.

Fig 4 – Select MVC template and check Web API in add folders and core references
Check Web API and click OK under Add folders and core references and leave Authentication to Individual User Accounts:
Add a filter named BasicAuthorizeAttribute, inheriting AuthorizeAttribute and replace the code with the one given in the following:
namespace Chapter05.BasicAuthentication...
Change the font size
Change margin width
Change background colour