Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am building a login system to improve my coding skills in .NET.
Currently i am building the project in Azure Functions.
The Azure Functions version i am using runs on .NET core 3.1.
The problem that i have is that i am unable to find a sessions and cookies class/library in the .NET Core framework. The classes that exists are part of ASP.NET Core. ASP.NET Core is not included in Azure Functions.
I have already tried to search for libraries that allow this functionality, however i was not successful.
How can i create sessions and cookies in Azure Functions?
Thank you in advance.
Firstly, the primary use cases for Azure Functions are stateless, and sessions are a bit against this principle.
If you insist on this, you could use
HttpRequestMessage
to implement it, the below is my test code.
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
log.LogInformation("C# HTTP trigger function processed a request.");
var resp = new HttpResponseMessage();
var cookie = new CookieHeaderValue("session-id", "12345");
cookie.Expires = DateTimeOffset.Now.AddDays(1);
cookie.Domain = req.RequestUri.Host;
cookie.Path = "/";
resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });
return resp;
And below is my result picture, help this is what you want if you still have other problem please feel free to let me know.
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.