How to change the idle logout time in Orchard Core - Orchard Core Nuggets

Zoltán Lehóczky's avatar
Orchard Core Nuggets, Orchard Core

Keeping user accounts secure is important. One aspect of this is to constrain how long people can remain logged in: If they share a device, especially a public one, then it's better to be on the safe side and automatically log them out after some time of inactivity. Here is how you can do it in Orchard Core!

Since an Orchard Core-using app is in the end just an ASP.NET Core app, you can use the standard Identity options to configure how user sessions work. What governs how long users remain logged in is mostly the cookie settings. This is how you can set it from the Program file of your web app:

builder.Services
    .AddOrchardCms()
    .ConfigureServices(services =>
        services.ConfigureApplicationCookie(options => options.ExpireTimeSpan = TimeSpan.FromMinutes(30)));

This logs users out after 30 minutes of inactivity. You can also set options.SlidingExpiration = false if you'd like this to be counted from the time they logged in, as opposed to the last time they did something in the app.

While the above example shows how to do this in the root web app, you can similarly set this from the Startup class of a module or theme.

That's it! It's worth checking out the official Orchard Core docs on configuring other Identity options too.

Did you like this post? It's part of our Orchard Core Nuggets series where we answer common Orchard questions, be it about user-facing features or developer-level issues. Check out the other posts for more such bite-sized Orchard Core tips and let us know if you have another question!

No Comments

Add a Comment