• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

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