Session state

Session state, as opposed to application state, keeps user-specific data for the duration that they are using the application. ASP.NET Core 3 makes use of the session middleware, which is configured in the ConfigureServices method in the Startup class by adding services.AddSession().

Before using the session object across your application, you need to add app.UseSession() to the Configure method in the Startup class.

By doing this, you can access the session object through HttpContext.Session, where you can utilize its methods to get or set your session variables or properties.

We have already mentioned that the session state is a server-based state management option, and that means everything you set will be handled by the server. Note that you can actually store your session data in a cookie as an option in the AddSession(option) method, like so:

services.AddSession(options => {options.Cookie.Name = "yourCustomSessionName";});

We are going to make use of session state in our game sessions later in this book by using the following code:

            services.AddSession(o =>
{
o.IdleTimeout = TimeSpan.FromMinutes(30);

});

The preceding code snippet is adding a session with a 30-minute timeout to the service collection in the ConfigureServices method. To be able to use this session, we will need to configure app.UseSession(), which can be found in the Configure method in the Startup class. More about sessions will be covered when we configure the game sessions in Chapter 8, Creating Web API applications, specifically in the Building RPC-style web APIs section. 

Now that we have an idea of state management, let's have a look at the different types of views that we can make use of to give our application users a proper user interface (UI) and a good user experience (UX).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.67.5