> For the complete documentation index, see [llms.txt](https://eleven-fifty-academy.gitbook.io/dotnet-201-elevennote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eleven-fifty-academy.gitbook.io/dotnet-201-elevennote/elevennote-api-parts-13-19/part-14-webapi/14.0-webapisetup.md).

# 14.0: WebAPI Setup

## 14.0: Web API Project

In this section, we will set up the WebAPI.

1. Right click on the solution and **Add -> New Project**
2. Choose **ASP.NET Web Application.**
3. Name it **ElevenNote.WebApi,** like the following screenshot:

   ![WebAPI Project](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxoltoX_ihZbOYkUnI%2F-LAxoneMd3G-l1PhdFdY%2F14.0-A.png?generation=1524676904198067\&alt=media)
4. In the menu(see below), select **Web API.**
5. Change the Authentication to **Individual User Accounts.** Notice and memorize that the API option is in the same view as the Web MVC menu. It's easy to forget.

   ![WebAPI Settings](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxoltoX_ihZbOYkUnI%2F-LAxong5mUEB0lYPy8JI%2F14.0-B.png?generation=1524676904072921\&alt=media)
6. Click OK and it will scaffold out the **Web API** project.

## WebAPI Setup

1. **Important** before running:
   * Copy the connection string from the **ElevenNote.WebMvc** `Web.config` file. This is the same we've been using throughout the app.&#x20;
   * Paste it into the **ElevenNote.WebAPI** `Web.config` file in place of what is there
   * If you haven't already, you can remove the .mdf file from the connection string.

     ![Remove mdf](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxoltoX_ihZbOYkUnI%2F-LAxonjtkJ066BN59Li4%2F14.0-C.png?generation=1524676904050063\&alt=media)
2. Set **ElevenNote.WebAPI** as the startup project
3. Right click on **ElevenNote.WebAPI** and choose **Add > Reference**
4. Select the **Data, Models, and Services** projects.
5. Open **ElevenNote.Data -> IdentityModels.cs.**
6. Paste this code inside the `ApplicationUser` class:

   ```csharp
            // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
            // Add custom user claims here
            return userIdentity;
        }
   ```
7. Here is a screenshot for context:

   ![Code](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxoltoX_ihZbOYkUnI%2F-LAxonqUCQkYTlzx7JaH%2F14.0-D.png?generation=1524676904352119\&alt=media)
8. Open **ElevenNote.WebAPI -> App\_Start -> WebApiConfig.cs**
   * This handles the routing of the API routes
9. Run the app
10. Click on API

    ![API](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxoltoX_ihZbOYkUnI%2F-LAxonu2bv8b6E3mLFSa%2F14.0-E.png?generation=1524676904204906\&alt=media)
11. This is an automatically generated document listing your API endpoints
12. Close the app
13. Go to **ElevenNote.WebAPI -> Models** and delete the `IdentityModels.cs` file, this is already in the database
14. `CTRL SHIFT B` to build the API. You should have a load of errors. Fix all of the errors with `CTRL .` to bring in the using statements. This is very similar to what you had to do when you created the MVC project. Notice  in the screenshot that IdentityModels.cs has been deleted in the WebApi project.

![](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LLlgXiGo2grJsMdaTF3%2F-LLlgb0H8k8Q-fZMkRdp%2Fimage.png?alt=media\&token=96910351-1dfa-476a-a178-f29530031457)

[Next,](/dotnet-201-elevennote/elevennote-api-parts-13-19/part-14-webapi/14.1-postmantest.md) we'll test the API with Postman.
