dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

net core session management problem

Open daltinkurt opened this issue 3 years ago • 1 comments

Hi everyone, I am trying to use sqlite caching. at localhost it works but at server session is active for only a few seconds.

I tried many alternatives by changing the order of the rows. what am i doing wrong?

here ise my startup.cs (.net core 3.1)

public class Startup
{
    private readonly IConfiguration Configuration;
    private readonly IWebHostEnvironment Env;

    public Startup(IConfiguration configuration, IWebHostEnvironment env)
    {
        Configuration = configuration;
        this.Env = env;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<JICEntities>(
                options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
                    opt =>
                    {
                        opt.ServerVersion(Configuration.GetConnectionString("DefaultConnectionVer"));
                    }
            ));

        var cachePath = "";
        if (Env.IsDevelopment())
        {
            cachePath = AppDomain.CurrentDomain.BaseDirectory + "cachedb\\JIC_Cache.sqlite";
        }
        else
        {
            var rootPath = Env.ContentRootPath;
            cachePath = Path.Combine(rootPath, "cachedb", "JIC_Cache.sqlite");
        }
        services.AddSqliteCache(options =>
        {
            options.CachePath = cachePath;
            options.CleanupInterval = TimeSpan.FromMinutes(20);
        });

        services.AddSession(options =>
        {
            options.Cookie.Name = ".JIC.Session";
            options.IdleTimeout = TimeSpan.FromMinutes(20);
            //options.Cookie.HttpOnly = true;
            options.Cookie.IsEssential = true;
        });

        services.AddDataProtection();
        //services.AddAuthorization();
        services.AddWebEncoders();
        services.AddDotVVM<DotvvmStartup>();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseSession();

        var dotvvmConfiguration = app.UseDotVVM<DotvvmStartup>(env.ContentRootPath);
        dotvvmConfiguration.AssertConfigurationIsValid();

        app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(env.WebRootPath)
        });
    }
}

daltinkurt avatar Mar 16 '21 12:03 daltinkurt

Sorry for the delay in response.

I tried to reproduce the issue (both locally and on a server), but it seems to be working in my case, so I believe this has something to do with the server configuration.

Are you still facing the issue? Can you somehow get to the console logs on the server? If it is running on IIS, I believe you can enable logging to a file in web.config. Can you check the cookie actually arrives on the server?

tomasherceg avatar Jul 22 '21 20:07 tomasherceg

I don't think there is anything we can do without further information, I'm closing the issue. Feel free to create a new one if you still face the problem.

exyi avatar Oct 07 '23 08:10 exyi