I want to read session id in application error event but always get error "Session state is not available in this context". Why? The strange thing is that I have the same code in another asp.net app and everything works fine.
void Application_Error(object sender, EventArgs e) { var sessionId = Session.SessionID; //skipped code }
To enable in-process session state by using the UIOpen IIS Manager and navigate to the level you want to manage. In Features View, double-click Session State. On the Session State page, in the Session State Mode Settings area, click In process.
Session state is an ASP.NET Core scenario for storage of user data while the user browses a web app. Session state uses a store maintained by the app to persist data across requests from a client. The session data is backed by a cache and considered ephemeral data.
web configuration section. You can also configure session state by using the EnableSessionState value in the @ Page directive. The sessionState element enables you to specify the following options: The mode in which the session will store data.
Off mode, which disables session state.
The session object may not be available this is dependent on when the error occured.
For example if an error occured on Begin_Request the session would not be available as it has not yet been created.
So in summary sometimes it will work sometimes not, depending on when the error occured.
Best to check the state of the session object before accesssing the session id e.g.
HttpContext context = HttpContext.Current; if (context != null && context.Session != null) ...
check if any event missing in c# which is mapped to a control or issue in design part
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With