Te doy la bienvenida a nuestra comunidad, ahora vas a encontrar la solucíon que estabas buscando.
Ejemplo 1: sesión principal de .net
publicclassIndexModel:PageModel{publicconststring SessionKeyName ="_Name";publicconststring SessionKeyAge ="_Age";conststring SessionKeyTime ="_Time";publicstring SessionInfo_Name get;privateset;publicstring SessionInfo_Age get;privateset;publicstring SessionInfo_CurrentTime get;privateset;publicstring SessionInfo_SessionTime get;privateset;publicstring SessionInfo_MiddlewareValue get;privateset;publicvoidOnGet(){// 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);
Ejemplo 2: sesión principal de .net
publicvoidConfigureServices(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();
Ejemplo 3: sesión principal de .net
publicclassStartuppublicStartup(IConfiguration configuration)
Configuration = configuration;publicIConfiguration Configuration get;publicvoidConfigureServices(IServiceCollection services)
services.AddDistributedMemoryCache();
services.AddSession(options =>
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly =true;
options.Cookie.IsEssential =true;);
services.AddControllersWithViews();
services.AddRazorPages();publicvoidConfigure(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(););
Sección de Reseñas y Valoraciones
Tienes la opción de añadir valor a nuestra información aportando tu experiencia en las interpretaciones.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)