.net core session
C#
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.Cookie.Name = ".AdventureWorks.Session";
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.IsEssential = true;
});
services.AddControllersWithViews();
services.AddRazorPages();
}
public class IndexModel : PageModel
{
public const string SessionKeyName = "_Name";
public const string SessionKeyAge = "_Age";
const string SessionKeyTime = "_Time";
public string SessionInfo_Name { get; private set; }
public string SessionInfo_Age { get; private set; }
public string SessionInfo_CurrentTime { get; private set; }
public string SessionInfo_SessionTime { get; private set; }
public string SessionInfo_MiddlewareValue { get; private set; }
public void OnGet()
{
// Requires: using Microsoft.AspNetCore.Http;
if (string.IsNullOrEmpty(HttpContext.Session.GetString(SessionKeyName)))
{
HttpContext.Session.SetString(SessionKeyName, "The Doctor");
HttpContext.Session.SetInt32(SessionKeyAge, 773);
}
var name = HttpContext.Session.GetString(SessionKeyName);
var age = HttpContext.Session.GetInt32(SessionKeyAge);
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
services.AddControllersWithViews();
services.AddRazorPages();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapRazorPages();
});
}
}
Also in C#:
- Title
- make camera follow character unity 2020
- Category
- C#
- Title
- c# MessageBox
- Category
- C#
- Title
- c sharp tryparse
- Category
- C#
- Title
- unity up arrow input
- Category
- C#
- Title
- as c#
- Category
- C#
- Title
- c# duplicate object instance
- Category
- C#
- Title
- c# throw new exception
- Category
- C#
- Title
- unity how to check object position
- Category
- C#
- Title
- c# empty char
- Category
- C#
- Title
- how to make pressing enter an event in c#
- Category
- C#
- Title
- c# reverse string
- Category
- C#
- Title
- unity mobile controls
- Category
- C#
- Title
- c# get motherboard id
- Category
- C#
- Title
- unity detect number key
- Category
- C#
- Title
- how to get component in unity c#
- Category
- C#
- Title
- windows forms iterate through all controls
- Category
- C#
- Title
- how to initiate a varaible in cs
- Category
- C#
- Title
- c# rsa example
- Category
- C#
- Title
- C# sprint key
- Category
- C#
- Title
- How to execute script in C#
- Category
- C#
- Title
- bash if null or empty
- Category
- C#
- Title
- unity reset scene
- Category
- C#
- Title
- how to trim path in C#
- Category
- C#
- Title
- c# counting lines
- Category
- C#
- Title
- c# start process
- Category
- C#
- Title
- how to make a float in C++
- Category
- C#
- Title
- how to insert <input> datatype <td> in asp.net core table
- Category
- C#
- Title
- visual studio c# mark class deprecated
- Category
- C#
- Title
- c# size of enum
- Category
- C#
- Title
- month number to text in c#
- Category
- C#
- Title
- switch case c# range
- Category
- C#
- Title
- unity find gameobject with layer
- Category
- C#
- Title
- create a file in the directory of the exe and write to it c#
- Category
- C#
- Title
- c sharp comments
- Category
- C#
- Title
- check if two timespans intersect c#
- Category
- C#
- Title
- cshtml foreach
- Category
- C#
- Title
- unity assign button onclick
- Category
- C#
- Title
- c# display image
- Category
- C#
- Title
- c# integer to bit string
- Category
- C#
- Title
- combine two arraylist c#
- Category
- C#
- Title
- Unity C# make object face away
- Category
- C#
- Title
- dont destroy on load unity
- Category
- C#
- Title
- bulk update in c# using jquery datatble
- Category
- C#
- Title
- beard styles without mustache Intitle:work with me
- Category
- C#
- Title
- c# round number
- Category
- C#
- Title
- Microsoft.AspNetCore.Components.Forms.InputSelect`1.TryParseValueFromString(String value, TValue& result, String& validationErrorMessage)
- Category
- C#
- Title
- delay in unity
- Category
- C#
- Title
- c# reverse a string for loop
- Category
- C#
- Title
- unity rb.addexplosionforce 2d
- Category
- C#
- Title
- C# downloadstirng download old
- Category
- C#
- Title
- C# resize window without title bar
- Category
- C#
- Title
- how to make error sound c#
- Category
- C#
- Title
- c# format number with leading zeros
- Category
- C#
- Title
- c# replace foreach with lambda
- Category
- C#
- Title
- c# send email
- Category
- C#
- Title
- unity 2d enemy field of view
- Category
- C#
- Title
- snake game
- Category
- C#
- Title
- wpf restart application c#
- Category
- C#
- Title
- unity get all children
- Category
- C#
- Title
- csharp check if env is development
- Category
- C#
- Title
- x angle oes back after 90 unity
- Category
- C#
- Title
- convert int to double c#
- Category
- C#
- Title
- .net identity seed users and roles
- Category
- C#
- Title
- c# postfix increment operator overload
- Category
- C#
- Title
- unity rotate object relative to camera
- Category
- C#
- Title
- c# string list contains
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- C# get all child classes of a class
- Category
- C#
- Title
- c# set session variable
- Category
- C#
- Title
- check version of asp.net core
- Category
- C#
- Title
- player script unity
- Category
- C#
- Title
- what is the and in c#
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- c# split large file into chunks
- Category
- C#
- Title
- c# distinct array of objects by values
- Category
- C#
- Title
- c# thread sleep
- Category
- C#
- Title
- c# tuple access
- Category
- C#
- Title
- unity set position
- Category
- C#
- Title
- c# static meaning
- Category
- C#
- Title
- c# length 2d array
- Category
- C#
- Title
- while loop c#
- Category
- C#
- Title
- unity deactive all object in list
- Category
- C#
- Title
- how to add object in dictionary in c#
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- c# edit element in list
- Category
- C#
- Title
- c# request run as administrator
- Category
- C#
- Title
- list clone - C#
- Category
- C#
- Title
- c# discord bot
- Category
- C#
- Title
- unity3d quaternion add 90 degrees
- Category
- C#
- Title
- fps controller c#
- Category
- C#
- Title
- how to name GameObject in c#
- Category
- C#
- Title
- error CS0542
- Category
- C#
- Title
- c# linq select specific columns
- Category
- C#
- Title
- c# store generic type without arguments
- Category
- C#
- Title
- c# bitmap to picturebox
- Category
- C#
- Title
- c# merge two xml files
- Category
- C#
- Title
- mvc write to console
- Category
- C#
- Title
- how to display an image url in c# picturebox
- Category
- C#
- Title
- ihttpactionresult to object c#
- Category
- C#
- Title
- prefab gets character transform
- Category
- C#