ASP.NET Core Hosting Tips: Create Custom Session ID Manager

In ASP.Net, the SessionIDManager class is used to generate and validate the Session ID. By default, it is saved in a cookie with the name ASP.NET_SessionId.

Get session ID by HttpContext class like below.


This session id is randomly generated and encoded with 24 characters containing lowercase a to z and numbers 0 to 5.

Suppose there is a scenario for customizing the session ID  and its validation. In that case, the developer can inherit the SessionIDManager class to a custom class and provide implementation to generate and validate the session ID.

We will do the same in the below code

using System;
using System.Configuration;
using System.Web.Configuration;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SampleProject.Custom
    public class CustomSessionIDManager : SessionIDManager
        public override string CreateSessionID(HttpContext context)
            string sessionId = Guid.NewGuid().ToString();
            return sessionId;

        public override bool Validate(string id)
            bool isValidId = id == HttpContext.Current.Session.SessionID;
            return isValidId;

And need to mention in web.config –> SessionState

<sessionState sessionIDManagerType="SampleProject.Custom.CustomSessionIDManager"></sessionState>

Now whenever an application creates a session, it will refer to CustomSessionIDManager.


In this article, we understood a bit about SessionIDManager and how to customize it. I hope it helps.

Best ASP.NET Core 7.0.2 Hosting Recommendation

One of the most important things when choosing a good ASP.NET Core 7.0.2 hosting is the feature and reliability. HostForLIFE is the leading provider of Windows hosting and affordable ASP.NET Core 7.0.2 , their servers are optimized for PHP web applications such as the latest ASP.NET Core 7.0.2 version. The performance and the uptime of the ASP.NET Core 7.0.2 hosting service are excellent and the features of the web hosting plan are even greater than what many hosting providers ask you to pay for. At HostForLIFEASP.NET, customers can also experience fast ASP.NET Core 7.0.2 hosting. The company invested a lot of money to ensure the best and fastest performance of the datacenters, servers, network and other facilities. Its datacenters are equipped with the top equipments like cooling system, fire detection, high speed Internet connection, and so on. That is why HostForLIFEASP.NET guarantees 99.9% uptime for ASP.NET Core 7.0.2. And the engineers do regular maintenance and monitoring works to assure its ASP.NET Core 7.0.2 hosting are security and always up.