I am trying to create a cookie.
I Run asp net core on host port: 44332
and the the front-end reactjs on port 3000
(for some reason im not allowed to put the code in a code block)
Loading
I am trying to create a cookie.
I Run asp net core on host port: 44332
and the the front-end reactjs on port 3000
(for some reason im not allowed to put the code in a code block)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
osyris zosarPosted Aug 7, 2021, 1:23 PM
osyris zosarPosted Aug 4, 2021, 3:19 PM
ConfigureServices:
services.AddControllers();(options =>
services.AddDbContext
options.UseSqlServer(Configuration.GetConnectionString("Database")));
services.AddIdentity()()
.AddEntityFrameworkStores
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Domain = "http://localhost";
options.Cookie.Name = ".AspNet.SharedCookie";
options.Cookie.Path = "/";
});
services.AddCors(options =>
{
options.AddPolicy(name: "ReactChat",
builder =>
{
builder.AllowAnyMethod()
.WithOrigins("http://localhost:3000")
.AllowAnyHeader()
.AllowCredentials();
});
});
services.AddSignalR();
Controller:
Login(LoginDto dto)
[HttpPost("login")]
public async Task
{
string newGuid = Guid.NewGuid().ToString();
HttpContext.Response.Cookies.Append("Login", newGuid, new CookieOptions
{
SameSite = SameSiteMode.None,
Domain = "http://localhost/"
//HttpOnly = false
}); ;
return Ok();
}