- Server operating system version
- Can't find it
- Plesk version and microupdate number
- Can't find it
Hello,
I've been making a project that requires logging in. But after couple of seconds, it logs out in Plesk environment. No problems in local env.
So far;
-Added SQL DataProtectionKeys API
-Modified program.cs at least 15 times, tried most of the things i could think/find online
-Changed session settings in plesk>asp.net settings>session
-Looked up for other settings in plesk panel, i think my hosting provider prohibited some of the settings
-Opened up a ticket in hosting provider website, they said they "resolved" it(no details provided), but nothing changed
This is how i check out for session;
My program.cs;
I've been making a project that requires logging in. But after couple of seconds, it logs out in Plesk environment. No problems in local env.
So far;
-Added SQL DataProtectionKeys API
-Modified program.cs at least 15 times, tried most of the things i could think/find online
-Changed session settings in plesk>asp.net settings>session
-Looked up for other settings in plesk panel, i think my hosting provider prohibited some of the settings
-Opened up a ticket in hosting provider website, they said they "resolved" it(no details provided), but nothing changed
This is how i check out for session;
C#:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace CoffeeShop.Admin.Filters;
public class AdminAuthorizeAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
var isLoggedIn = context.HttpContext.Session.GetString("admin");
if (string.IsNullOrEmpty(isLoggedIn))
{
context.Result = new RedirectToActionResult("Login", "Auth", null);
}
base.OnActionExecuting(context);
}
}
My program.cs;
C#:
using CoffeeShop.Business.Interfaces;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<CoffeeDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddScoped<ICategoryService, CategoryService>();
builder.Services.AddScoped<IProductService, ProductService>();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromHours(5);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Cookie.SameSite = SameSiteMode.Lax;
});
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.AddServerHeader = false;
});
builder.Services.AddDataProtection()
.PersistKeysToDbContext<CoffeeDbContext>();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseSession();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();