How to obtain a cookie in the Web API in a Forms Authentication scenario in Cross Application?

Asked

Viewed 75 times

4

I have the following applications . Net:

  1. Web Application with Forms Authentication (I’m not using MVC, I use Backbone.js to call the REST API)
  2. Web API REST application sharing the same Forms Authenticaion used in application 1.

I am using the same machineKey in both projects so that the cookie is unique in both. reference

The single cookie settings in both applications seem to be working (I’m not sure), but how do I get the cookie in the Web API application?

2 answers

1

To get the cookie from a Webapi controller just use Request.Headers.GetCookies('nome do cookie')

0

This is only possible if both applications are on the same server and sharing the same virtual directory.

Any scenario other than that will not be possible. So, if you are hosting in the cloud, you can already discard.

If you are following the above criteria, just define the PATH of the cookie as / both applications will consume the same cookies.

  • The scenario is already as you described it. What I need is to know how to get the cookie via code in the Web API application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.