I would like to create a demo login service in web api and need to set a cookie on the response. How do I do that? Or are there any better way to do authorization?
相关问题
- Register MicroServices in Azure Active Directory (
- PromptDialog Choice with List object Bot Framework
- Dotnet Core API - Get the URL of a controller meth
- Serving data with “transfer-encoding: chunked” on
- StringEnumConverter invalid int values
相关文章
- POSTing data to WebApi after update to 5.1.0 fails
- Can you use generic methods in a controller?
- Remove a route with IOperationFilter in SwashBuckl
- Validate fails in unit tests
- C# HttpClient.SendAsync always returns 404 but URL
- subdomain CORS in webApi 2
- Post Array Json to .net core web api controller [d
- How can I read JSON from a StringContent object in
Add a reference to
System.Net.Http.Formatting.dll
and use theAddCookies
extension method defined in theHttpResponseHeadersExtensions
class.Here is a blog post describing this approach, and the MSDN topic.
If that assembly isn't an option for you, here's my older answer from before this was an option:
Older answer follows
I prefer an approach that stays within the realm of
HttpResponseMessage
without bleeding into the HttpContext which isn't as unit testable and does not always apply depending on the host:Then you can include a cookie in the response like this:
You can add the cookie to the HttpContext.Current.Response.Cookies collection.