• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Issue Session Problem

ikosedev

New Pleskian
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;

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();
 
Okay so i contacted my hosting provider again and it seems fixed right now. This was their response, have no clue what they did.

Hello,

In order to help you and to resolve the relevant error, synchronization has been provided on the IIS side throughout the entire server.
 
Back
Top