Session
To enable session storage, call the AddSqlSession()
extension method of the IServiceCollection
, passing the same connection string that is used for the Entity Framework database context, for example:
services.AddSqlSession( configuration.GetConnectionString( "ApplicationDbContextConnection" ) );
This method configures the distributed cache provider for the SQL Server and the ISessionStore
service which is part of ASP.NET Core.
The SqlSessionOptions
class contains settings related to sessions. They can be changed by passing a callback to the AddSqlSession()
method, or by adding a SqlSessionOptions
section to the appsettings.json
file.
CookieName
— the name of the cookie storing session information. The default value is".BC.Session"
.ExprireTimeSpan
— the expiration time of the cookie and the session data. The default value is 2 hours.ConnectionString
— the connection string used by the distributed cache provider. It can be passed directly to theAddSqlSession()
method.
By default, the ISession
only makes it possible to store binary data. Bulletcode.NET adds the SetObject()
and GetObject()
extension methods to ISession
, which make it possible to store and retrieve an arbitrary object, which is serialized to JSON.
The AddFrontViewServices()
extension method for IMvcBuilder
adds support for temporary data. It registers the standard temporary data provider which stores temporary data in session state, and registers a custom temporary data serializer which converts temporary data into a binary stream.
Only binary data can be stored in the ITempDataDictionary
, but Bulletcode.NET adds extension methods to this interface which make it possible to store other types of data:
SetInt32()
,GetInt32()
,PeekInt32()
— for integer valuesSetString()
,GetString()
,PeekString()
— for stringsSetObject()
,GetObject()
,PeekObject()
— for arbitrary objects, which are serialized to JSON
The BaseController
uses temporary data to store flash alerts. They can be added using the FlashSuccess()
, FlashWarning()
and FlashError()
methods.
The "_FlashAlerts"
partial view can be used to render the flash alerts:
<partial name="_FlashAlerts" />
In ClientView applications, the FlashAlerts
component can be used.