# How to test ASP.NET Core Web API with cookie authentication using Postman?

**URL:** <https://community.postman.com/t/how-to-test-asp-net-core-web-api-with-cookie-authentication-using-postman/4809>\
**Category:** Help Hub\
**Tags:** authentication, cookies\
**Created:** [April 2, 2019, 5:18pm UTC](https://community.postman.com/t/how-to-test-asp-net-core-web-api-with-cookie-authentication-using-postman/4809 "2019-04-02T17:18:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopher.d.keith](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/christopher.d.keith/32/1537_2.png) [@christopher.d.keith](https://community.postman.com/u/christopher.d.keith)\
**Post date:** [April 2, 2019, 5:18pm UTC](https://community.postman.com/t/how-to-test-asp-net-core-web-api-with-cookie-authentication-using-postman/4809/1 "2019-04-02T17:18:25Z")

</div>

Hi All.

I posted this on [Stack Overflow](https://stackoverflow.com/q/55473852/4464993) as a Q&A post; however, I don’t think it’ll be around for much longer… So I’m posting it here.

I’m working on a [ASP.NET](http://ASP.NET) Core MVC Web Application (.NET Core 2.1) that implements Cookie Authentication. The web application also includes a web API where client-side JavaScript makes Ajax calls back to the web server. The web API is not intended to be consumed by external systems, not at the moment; however, it be a different story if it did i.e. an appropriate authentication method for a stateless service.

The web API controllers are decorated with `[Authorize]`; requiring the user to login via the web application before the Ajax calls can access the web API methods.

I wanted to use Postman (Windows native application) to test the web API calls while running the web application on localhost. I couldn’t find any articles or how-to posts that pointed out what needs to happen to get this working. So I documented the following steps:

How to copy the authentication cookie into Postman from the browser after logging in?

1. Run and log into your web application and open the Browser’s Developer Tools.

2. From Developer Tools, locate the list of cookies for localhost. Using Chrome (version 73) as an example, select the Application tab and expand the Storage \> Cookies option.

3. From the Cookies option, click on your localhost web application e.g. localhost:port. This will display the list of cookies.

4. Having logged into your web application, a cookie named `.AspNetCore.Cookies` should be present. Copy the value i.e. it should be a long string of characters such as `CfDJ8FNwIhImGGFJmGnb...`

5. From Postman, create a request to access your chosen web API method and locate the Cookies option for the request.

6. From within Manage Cookies, add a new cookie. Example from Postman (v7.0.6) below  

7. The placeholder value should be updated from:

8. Click send. The response should be the data or error returned from the web API method call and not the HTML of your login page. If it’s the login page HTML, then the cookie or cookie value is most likely incorrect.

I know this is not how web API authentication should be implemented; however, this post is about setting up Postman to work in the particular scenario. This is the second time I’ve come across this situation and have decided to document it.

---

<div class="post-metadata">

**Author:** ![ian.coetzer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ian.coetzer/32/3105_2.png) [@ian.coetzer](https://community.postman.com/u/ian.coetzer)\
**Post date:** [October 27, 2019, 4:50pm UTC](https://community.postman.com/t/how-to-test-asp-net-core-web-api-with-cookie-authentication-using-postman/4809/2 "2019-10-27T16:50:14Z")

</div>

Thank you for this useful post. For now I will use this method to test my API

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 2:46pm UTC](https://community.postman.com/t/how-to-test-asp-net-core-web-api-with-cookie-authentication-using-postman/4809/3 "2024-12-12T14:46:54Z")

</div>

Closed on December 12, 2024, 2:46pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
