| @* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| *@ |
| @page |
| @using Microsoft.AspNetCore.Http |
| @model IndexModel |
| @{ |
| ViewData["Title"] = "Asp.Net Core Session Sample"; |
| } |
| |
| <h1>@ViewData["Title"]</h1> |
| |
| <h2>State management</h2> |
| |
| <div class="row"> |
| <div class="col-md-8"> |
| <form method="post"> |
| <div class="panel panel-default"> |
| <div class="panel-heading"> |
| <button type="submit" asp-page-handler="ChangeAge" class="pull-right btn btn-danger">Change Age</button> |
| <h3 class="panel-title" style="line-height:2.1">Name and Age</h3> |
| </div> |
| <div class="panel-body"> |
| <p> |
| The name and age are stored in session. Select the <span style="font-weight:bold">Change Age</span> |
| button to update the session to a new random age value. |
| </p> |
| <p> |
| Session values by the model with |
| <code>@@Model.<PropertyName></code>: |
| </p> |
| <p><b>Name:</b> @Model.SessionInfo_Name <b>Age:</b> @Model.SessionInfo_Age</p> |
| <hr> |
| <p>Session values direct </p> |
| <p> |
| <b>Name:</b> @HttpContext.Session.GetString(IndexModel.SessionKeyName) |
| <b>Age:</b> |
| @HttpContext.Session.GetInt32(IndexModel.SessionKeyAge).ToString() |
| </p> |
| </div> |
| </div> |
| </form> |
| </div> |
| </div> |
| |
| <div class="row"> |
| <div class="col-md-8"> |
| <div class="panel panel-default"> |
| <div class="panel-heading"> |
| <h3 class="panel-title">HttpContext.Items Middleware Value</h3> |
| </div> |
| <div class="panel-body"> |
| <p> |
| The middleware value is set into the <code>HttpContext.Items</code> collection by |
| the <code>HttpContextItemsMiddleware</code> before Razor Pages processes the request. |
| The value is retreived by the page and displayed. |
| </p> |
| <p>Value: @Model.SessionInfo_MiddlewareValue</p> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <div class="row"> |
| <div class="col-md-8"> |
| <form method="post"> |
| <div class="panel panel-default"> |
| <div class="panel-heading clearfix"> |
| <button type="submit" asp-page-handler="UpdateSessionDate" class="pull-right btn btn-danger">Update Session Time</button> |
| <a href="/" class="pull-right btn btn-danger" style="margin-right:5px">Reload Page (No Update)</a> |
| <h3 class="panel-title" style="line-height:2.1">Session Time</h3> |
| </div> |
| <div class="panel-body"> |
| <p> |
| The session time is stored in session. Select the <span style="font-weight:bold"> |
| Reload Page (No Update) |
| </span> button to display the current time and the time stored in session. |
| Select the <span style="font-weight:bold">Update Session Time</span> button to store the current time in session. |
| </p> |
| <p>Current Time: @Model.SessionInfo_CurrentTime</p> |
| <p>Session Time: @Model.SessionInfo_SessionTime</p> |
| </div> |
| </div> |
| </form> |
| </div> |
| </div> |