You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.. note:: Since keys into ``Items`` are simple strings, if you are developing middleware that needs to work across many applications, you may wish to prefix your keys with a unique identifier to avoid key collisions (e.g. "MyComponent.isVerified" instead of just "isVerified").
@@ -108,7 +107,7 @@ ASP.NET ships with several implementations of ``IDistributedCache``, including a
108
107
109
108
.. code-block:: c#
110
109
111
-
services.AddCaching();
110
+
services.AddDistributedMemoryCache();
112
111
services.AddSession();
113
112
114
113
Then, add the following to ``Configure`` and you're ready to use session in your application code:
@@ -152,13 +151,15 @@ Once session is installed and configured, you refer to it via HttpContext, which
152
151
153
152
publicinterfaceISession
154
153
{
155
-
TaskLoadAsync();
156
-
TaskCommitAsync();
157
-
boolTryGetValue(stringkey, outbyte[] value);
158
-
voidSet(stringkey, byte[] value);
159
-
voidRemove(stringkey);
160
-
voidClear();
161
-
IEnumerable<string> Keys { get; }
154
+
boolIsAvailable { get; }
155
+
stringId { get; }
156
+
IEnumerable<string> Keys { get; }
157
+
TaskLoadAsync();
158
+
TaskCommitAsync();
159
+
boolTryGetValue(stringkey, outbyte[] value);
160
+
voidSet(stringkey, byte[] value);
161
+
voidRemove(stringkey);
162
+
voidClear();
162
163
}
163
164
164
165
Because``Session`` is built on top of ``IDistributedCache``, you must always serialize the object instances being stored. Thus, the interface works with ``byte[]`` not simply ``object``. However, there are extension methods that make working with simple types such as ``String`` and ``Int32`` easier, as well as making it easier to get a byte[] value from session.
@@ -184,7 +185,7 @@ The associated sample application demonstrates how to work with Session, includi
184
185
:language: c#
185
186
:lines: 15-23
186
187
:dedent: 8
187
-
:emphasize-lines:3,5-8
188
+
:emphasize-lines:2,6
188
189
189
190
When you first navigate to the web server, it displays a screen indicating that no session has yet been established:
190
191
@@ -195,7 +196,7 @@ This default behavior is produced by the following middleware in *Startup.cs*, w
0 commit comments