Reputation: 4662
If I created an Azure Function in isolate process mode, HttpRequestData.Cookies is empty. If I create exactly the same Function in non isolated mode it has cookies.
To illustrate my point. I created 2 functions. Both running on the same port (they are run independently).
(The functions were created with default VS 2021 templates and the only changes that was made is the function name)
From blazor the functions are simply called with.
In chrome I can see the cookies being passed:
(I started this journey trying to inject the ClaimsPrincipal as discussed in: https://www.youtube.com/watch?v=eZQq3zw3WL4. In an Isolated Azure function this value is null, and once again not in an Non Isolated Azure function. I'm assuming that this is because the auth cookie is not picked up)
EDIT: The accepted answer helps with fixing the empty claims issue. However even when the claims are present we don't get the ClaimsPrincipal injected. I found this article that describes a workaround: https://adamstorr.azurewebsites.net/blog/using-azure-functions-middleware-to-access-claimsprincipal-in-azure-static-web-apps
Upvotes: 2
Views: 2769
Reputation:
.Net 5 Isolated Http Trigger Azure Function:
Non-Isolated Function: .Net 3.1 Http Trigger Azure Function
As I observer a behavioral difference between In-Process (Non Isolated) and Out-Process (Isolated Environment), i.e., in the function declaration uses HttpRequest/ObjectResult in Non-Isolated and HttpRequestData/HttpResponseData in Isolated.
As given in the HttpRequestData
Class Microsoft Documentation, it gets the cookies of the request class.
Where as HttpRequest
Or the ObjectResult
classes are ASP .Net Core features to store the field like body, headers, cookies, content-type, content-length etc.,.
And the main usecase of Azure Functions are stateless. You can probably emulate it yourself by using Request.Cookies
and Response.Cookies
but ASP .NET features aren't directly applicable in Functions.
In the December Month of GitHub Issues Page of azure-functions-dotnet-worker, it is marked as a bug in the Azure Functions v3 that the HttpRequestData.Cookies is Empty but can be resolved when we specify the Cookies class from the request object or it can be resolved when we update the Microsoft.Azure.Functions.Worker
to 1.6.0
version.
Upvotes: 1