Introduction
This articles explains how to create a individual accounts in the ASP.NET Web API. This is related to the authentication and the security of the Web API. It is usually created for managing the local database. For this article we need the Fiddler tool for the HTTP request of the Web API.
Now see the following example.
Step 1
- Start Visual Studio 2013.
- From the Start Window select "New Project".
- Select "Installed" -> "Templates" -> "Visual C#" -> "Web" and select ASP.NET Web Application.
- From the ASP.NET project window select "WebAPI".
- Click on the "Change Authentication" button.
- From the Change Authentication dialog select "Individual User Accounts".
- Click on the "OK" button.
Step 2
Press F5 to execute the application. It displays the home page.
When the application is executed it uses a port number for the web server. Here the port number is "42506"
Step 3
Now send the HTTP request to the Web API.
- Now Open the Fiddler Tool.
- Select the "Composer" tab.
- And type the following URL "http://localhost:42506/api/values".
- Now click on the "Execute" button.
- After completing the request the response is displayed in the left panel.
It displays the 401 unauthorized because the valuesController is marked with the "[Authorize]" attribute. This attribute specifies tht the request of the controller must be from the authenticated user.
- Now double-click on the response. The detail is displayed in the inspector tab.
- In the detailed View click on the "Raw" tab for displaying the HTTP response.
Step 4
Register the user.
The Fiddler Tool looks like this:
Press "Execute" and now click on the Raw for seeing the HTTP request.