You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mm...@apache.org on 2021/07/28 00:00:19 UTC

[geode-dotnet-core-client] 01/03: GEODE-9464: Add a non-Steeltoe Asp.Net Core web app

This is an automated email from the ASF dual-hosted git repository.

mmartell pushed a commit to branch AddNonSteeltoeSample
in repository https://gitbox.apache.org/repos/asf/geode-dotnet-core-client.git

commit 6594f20bb85ac9c9ed6b7d94b6e48dbef3bffee7
Author: Mike Martell <mm...@pivotal.io>
AuthorDate: Tue Jul 27 16:46:00 2021 -0700

    GEODE-9464: Add a non-Steeltoe Asp.Net Core web app
---
 .../AspNetCore GeodeSession Sample.csproj          | 13 ++++
 .../Extensions/SessionExtensions.cs                | 44 +++++++++++++
 .../Middleware/HttpContextItemsMiddleware.cs       | 36 +++++++++++
 .../Models/BasicAuthInitialize.cs                  | 31 +++++++++
 .../Models/ErrorViewModel.cs                       | 11 ++++
 AspNetCore GeodeSession Sample/Pages/Error.cshtml  | 26 ++++++++
 .../Pages/Error.cshtml.cs                          | 23 +++++++
 AspNetCore GeodeSession Sample/Pages/Index.cshtml  | 72 +++++++++++++++++++++
 .../Pages/Index.cshtml.cs                          | 71 +++++++++++++++++++++
 .../Pages/Shared/_Layout.cshtml                    | 14 ++++
 .../Pages/_ViewImports.cshtml                      |  3 +
 .../Pages/_ViewStart.cshtml                        |  3 +
 AspNetCore GeodeSession Sample/Program.cs          | 17 +++++
 .../Properties/launchSettings.json                 | 28 ++++++++
 AspNetCore GeodeSession Sample/README.md           | 58 +++++++++++++++++
 .../SessionSampleNoSteeltoe.sln                    | 31 +++++++++
 AspNetCore GeodeSession Sample/Startup.cs          | 74 ++++++++++++++++++++++
 .../appsettings.Development.json                   |  9 +++
 .../appsettings.Production.json                    |  9 +++
 AspNetCore GeodeSession Sample/appsettings.json    | 17 +++++
 20 files changed, 590 insertions(+)

diff --git a/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj b/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj
new file mode 100644
index 0000000..a3ed1f8
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj	
@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <Platforms>AnyCPU;x64;x86</Platforms>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\NetCore.Session\NetCore.Session.csproj" />
+  </ItemGroup>
+
+
+</Project>
diff --git a/AspNetCore GeodeSession Sample/Extensions/SessionExtensions.cs b/AspNetCore GeodeSession Sample/Extensions/SessionExtensions.cs
new file mode 100644
index 0000000..8b5035e
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Extensions/SessionExtensions.cs	
@@ -0,0 +1,44 @@
+using System.Text.Json;
+using Microsoft.AspNetCore.Http;
+
+namespace Web.Extensions
+{
+    #region snippet1
+    public static class SessionExtensions
+    {
+        public static void Set<T>(this ISession session, string key, T value)
+        {
+            session.SetString(key, JsonSerializer.Serialize(value));
+        }
+
+        public static T Get<T>(this ISession session, string key)
+        {
+            var value = session.GetString(key);
+            return value == null ? default : JsonSerializer.Deserialize<T>(value);
+        }
+    }
+    #endregion      
+}
+
+namespace Web.Extensions2
+{
+    // Alternate approach
+
+    public static class SessionExtensions
+    {
+        public static void Set<T>(this ISession session, string key, T value)
+        {
+            session.SetString(key, JsonSerializer.Serialize(value));
+        }
+
+        public static bool TryGet<T>(this ISession session, string key, out T value)
+        {
+            var state = session.GetString(key);
+            value = default;
+            if (state == null)
+                return false;
+            value = JsonSerializer.Deserialize<T>(state);
+            return true;
+        }
+    }
+}
\ No newline at end of file
diff --git a/AspNetCore GeodeSession Sample/Middleware/HttpContextItemsMiddleware.cs b/AspNetCore GeodeSession Sample/Middleware/HttpContextItemsMiddleware.cs
new file mode 100644
index 0000000..6a8597c
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Middleware/HttpContextItemsMiddleware.cs	
@@ -0,0 +1,36 @@
+using System;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+
+namespace SessionSample.Middleware
+{
+    #region snippet1
+    public class HttpContextItemsMiddleware
+    {
+        private readonly RequestDelegate _next;
+        public static readonly object HttpContextItemsMiddlewareKey = new Object();
+
+        public HttpContextItemsMiddleware(RequestDelegate next)
+        {
+            _next = next;
+        }
+
+        public async Task Invoke(HttpContext httpContext)
+        {
+            httpContext.Items[HttpContextItemsMiddlewareKey] = "K-9";
+
+            await _next(httpContext);
+        }
+    }
+
+    public static class HttpContextItemsMiddlewareExtensions
+    {
+        public static IApplicationBuilder 
+            UseHttpContextItemsMiddleware(this IApplicationBuilder app)
+        {
+            return app.UseMiddleware<HttpContextItemsMiddleware>();
+        }
+    }
+    #endregion
+}
diff --git a/AspNetCore GeodeSession Sample/Models/BasicAuthInitialize.cs b/AspNetCore GeodeSession Sample/Models/BasicAuthInitialize.cs
new file mode 100644
index 0000000..c1b2a71
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Models/BasicAuthInitialize.cs	
@@ -0,0 +1,31 @@
+using Apache.Geode.NetCore;
+using System;
+using System.Collections.Generic;
+
+namespace GemFireSessionState.Models
+{
+  public class BasicAuthInitialize : IAuthInitialize
+  {
+    private string _username;
+    private string _password;
+
+    public BasicAuthInitialize(string username, string password)
+    {
+      _username = username;
+      _password = password;
+    }
+
+    public void Close()
+    {
+    }
+
+    public Dictionary<string, string> GetCredentials()
+    {
+      Console.WriteLine("SimpleAuthInitialize::GetCredentials called");
+      var credentials = new Dictionary<string, string>();
+      credentials.Add("security-username", "root");
+      credentials.Add("security-password", "root-password");
+      return credentials;
+    }
+  }
+}
\ No newline at end of file
diff --git a/AspNetCore GeodeSession Sample/Models/ErrorViewModel.cs b/AspNetCore GeodeSession Sample/Models/ErrorViewModel.cs
new file mode 100644
index 0000000..e67efeb
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Models/ErrorViewModel.cs	
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace SessionSample.Models
+{
+  public class ErrorViewModel
+  {
+  }
+}
diff --git a/AspNetCore GeodeSession Sample/Pages/Error.cshtml b/AspNetCore GeodeSession Sample/Pages/Error.cshtml
new file mode 100644
index 0000000..6f92b95
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/Error.cshtml	
@@ -0,0 +1,26 @@
+@page
+@model ErrorModel
+@{
+    ViewData["Title"] = "Error";
+}
+
+<h1 class="text-danger">Error.</h1>
+<h2 class="text-danger">An error occurred while processing your request.</h2>
+
+@if (Model.ShowRequestId)
+{
+    <p>
+        <strong>Request ID:</strong> <code>@Model.RequestId</code>
+    </p>
+}
+
+<h3>Development Mode</h3>
+<p>
+    Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
+</p>
+<p>
+    <strong>The Development environment shouldn't be enabled for deployed applications.</strong>
+    It can result in displaying sensitive information from exceptions to end users.
+    For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
+    and restarting the app.
+</p>
diff --git a/AspNetCore GeodeSession Sample/Pages/Error.cshtml.cs b/AspNetCore GeodeSession Sample/Pages/Error.cshtml.cs
new file mode 100644
index 0000000..3951f71
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/Error.cshtml.cs	
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace SessionSample.Pages
+{
+    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
+    public class ErrorModel : PageModel
+    {
+        public string RequestId { get; set; }
+
+        public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
+
+        public void OnGet()
+        {
+            RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
+        }
+    }
+}
diff --git a/AspNetCore GeodeSession Sample/Pages/Index.cshtml b/AspNetCore GeodeSession Sample/Pages/Index.cshtml
new file mode 100644
index 0000000..21346af
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/Index.cshtml	
@@ -0,0 +1,72 @@
+@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.&lt;PropertyName&gt;</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>
diff --git a/AspNetCore GeodeSession Sample/Pages/Index.cshtml.cs b/AspNetCore GeodeSession Sample/Pages/Index.cshtml.cs
new file mode 100644
index 0000000..83a5896
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/Index.cshtml.cs	
@@ -0,0 +1,71 @@
+using System;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using SessionSample.Middleware;
+using Web.Extensions;
+
+namespace SessionSample.Pages
+{
+    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, 35);
+            }
+
+            var name = HttpContext.Session.GetString(SessionKeyName);
+            var age = HttpContext.Session.GetInt32(SessionKeyAge);
+            SessionInfo_Name = name;
+            SessionInfo_Age = age.ToString();
+
+            var currentTime = DateTime.Now;
+
+            // Requires SessionExtensions from sample download.
+            if (HttpContext.Session.Get<DateTime>(SessionKeyTime) == default)
+            {
+                HttpContext.Session.Set<DateTime>(SessionKeyTime, currentTime);
+            }
+
+            SessionInfo_CurrentTime = currentTime.ToString("H:mm:ss tt");
+            SessionInfo_SessionTime = HttpContext.Session.Get<DateTime>(SessionKeyTime)
+                .ToString("H:mm:ss tt");
+
+            HttpContext.Items
+                .TryGetValue(HttpContextItemsMiddleware.HttpContextItemsMiddlewareKey, 
+                    out var middlewareSetValue);
+            SessionInfo_MiddlewareValue = 
+                middlewareSetValue?.ToString() ?? "Middleware value not set!";
+        }
+
+        public IActionResult OnPostUpdateSessionDate()
+        {
+            HttpContext.Session.Set<DateTime>(SessionKeyTime, DateTime.Now);
+
+            return RedirectToPage();
+        }
+
+        public IActionResult OnPostChangeAge()
+        {
+            var r = new Random();
+
+            HttpContext.Session.SetInt32(SessionKeyAge, r.Next(35, 65));
+
+            return RedirectToPage();
+        }
+    }
+}
diff --git a/AspNetCore GeodeSession Sample/Pages/Shared/_Layout.cshtml b/AspNetCore GeodeSession Sample/Pages/Shared/_Layout.cshtml
new file mode 100644
index 0000000..b761491
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/Shared/_Layout.cshtml	
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>@ViewData["Title"]</title>
+    <style>body{margin:0;padding-bottom:20px;font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff;}h1{font-size:24px;margin:.67em 0;}pre{overflow:auto;}code,pre{font-family:monospace, monospace;font-size:1em;}button,input{margin:0;font:inherit;color:inherit;}button{overflow:visible;}button{text-transform:none;}input{line-height:normal;}{box-sizing:border-box;}:before,*:after{box-sizing:border-box;}input,button{f [...]
+</head>
+<body>
+    <div class="container body-content">
+        @RenderBody()
+    </div>
+</body>
+</html>
diff --git a/AspNetCore GeodeSession Sample/Pages/_ViewImports.cshtml b/AspNetCore GeodeSession Sample/Pages/_ViewImports.cshtml
new file mode 100644
index 0000000..f22da06
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/_ViewImports.cshtml	
@@ -0,0 +1,3 @@
+@using SessionSample
+@namespace SessionSample.Pages
+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
diff --git a/AspNetCore GeodeSession Sample/Pages/_ViewStart.cshtml b/AspNetCore GeodeSession Sample/Pages/_ViewStart.cshtml
new file mode 100644
index 0000000..a5f1004
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Pages/_ViewStart.cshtml	
@@ -0,0 +1,3 @@
+@{
+    Layout = "_Layout";
+}
diff --git a/AspNetCore GeodeSession Sample/Program.cs b/AspNetCore GeodeSession Sample/Program.cs
new file mode 100644
index 0000000..6ab590d
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Program.cs	
@@ -0,0 +1,17 @@
+using Microsoft.AspNetCore;
+using Microsoft.AspNetCore.Hosting;
+
+namespace SessionSample
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            CreateWebHostBuilder(args).Build().Run();
+        }
+
+        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
+            WebHost.CreateDefaultBuilder(args)
+                .UseStartup<Startup>();
+    }
+}
diff --git a/AspNetCore GeodeSession Sample/Properties/launchSettings.json b/AspNetCore GeodeSession Sample/Properties/launchSettings.json
new file mode 100644
index 0000000..4ebabb5
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Properties/launchSettings.json	
@@ -0,0 +1,28 @@
+{
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://localhost:50795/",
+      "sslPort": 44315
+    }
+  },
+  "profiles": {
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "launchBrowser": true,
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      },
+      "nativeDebugging": true
+    },
+    "SessionSample": {
+      "commandName": "Project",
+      "launchBrowser": true,
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      },
+      "applicationUrl": "https://localhost:5001;http://localhost:5000"
+    }
+  }
+}
\ No newline at end of file
diff --git a/AspNetCore GeodeSession Sample/README.md b/AspNetCore GeodeSession Sample/README.md
new file mode 100644
index 0000000..38b0a9b
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/README.md	
@@ -0,0 +1,58 @@
+You can configure GeodeDistributedCache as a distributed cache for your ASP.NET Core application using either of the options described below.
+
+---
+NetCore-Session provides the AddGeodeDistributedCache() extension method on IServiceCollection, which requires just an Apache Geode region name and any optional configurations to store the sessions. 
+
+There are two methods to specify configurations:
+1. Through your application in Startup.cs or
+2. In JSON format in Appsettings.json of your application.
+   
+## Method 1: Specifying Configurations In Startup.cs
+
+The AddGeodeSessionStateCache() method is an extension of the AddDistributedCache() method provided by ASP.NET Core. This method takes configuration settings in Startup.cs of your application, or reads them from the specified JSON file.
+
+Add the following method and options in Startup.cs of your application:
+
+```c#
+public void ConfigureServices(IServiceCollection services)
+{
+    //Add framework services
+    services.AddMvc();
+
+    services.AddGeodeSessionStateCache(configuration =>
+    {
+        configuration.RegionName = "geodeSessionState";
+    });
+}
+```
+
+## Method 2: Specifying Configurations In appsettings.json
+You can also specify the configuration in JSON format using the appsettings.json file for your application. Using this method, you can refer to the configurations by providing the name of the section containing JSON format configurations in Startup.cs.
+
+appsettings.json:
+
+```json
+{
+  "AppSettings": {
+    "SiteTitle": "ASP.NET Core SessionState Sample App"
+  },
+
+  "GeodeSessionStateCache": {
+    "RegionName": "geodeSessionState",
+    "Host": "localhost",
+    "Port": 10334
+  }
+}
+```
+
+The ConfigureServices member of the Startup class can be used as follows to retrieve the GeodeSessionStateCache settings from the JSON file:
+
+```c#
+public void ConfigureServices(IServiceCollection services)
+{
+  ...
+  services.Configure<GeodeSessionStateCacheOptions>(
+    Configuration.GetSection("GeodeSessionStateCache"));
+  ...
+}
+```
diff --git a/AspNetCore GeodeSession Sample/SessionSampleNoSteeltoe.sln b/AspNetCore GeodeSession Sample/SessionSampleNoSteeltoe.sln
new file mode 100644
index 0000000..4f6c0fb
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/SessionSampleNoSteeltoe.sln	
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30028.174
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionSample", "SessionSample.csproj", "{0073CD89-8ED5-42DC-8C0F-88036A11AE91}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
+		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|Any CPU.ActiveCfg = Debug|x64
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|Any CPU.Build.0 = Debug|x64
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|x64.ActiveCfg = Debug|x64
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|x64.Build.0 = Debug|x64
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|Any CPU.Build.0 = Release|Any CPU
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|x64.ActiveCfg = Release|x64
+		{0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|x64.Build.0 = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {EA7D931C-E9EA-4F8A-B4EA-18C5322FC048}
+	EndGlobalSection
+EndGlobal
diff --git a/AspNetCore GeodeSession Sample/Startup.cs b/AspNetCore GeodeSession Sample/Startup.cs
new file mode 100644
index 0000000..1d4b4b4
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/Startup.cs	
@@ -0,0 +1,74 @@
+using Apache.Geode.Session;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Hosting;
+using SessionSample.Middleware;
+using Microsoft.Extensions.Caching.Distributed;
+using System;
+
+namespace SessionSample
+{
+    public class Startup
+    {
+        public Startup(IConfiguration configuration)
+        {
+            Configuration = configuration;
+        }
+
+        public IConfiguration Configuration { get; }
+        public ILoggerFactory LoggerFactory { get; }
+
+        public void ConfigureServices(IServiceCollection services)
+        {
+            services.Add(ServiceDescriptor.Singleton<IDistributedCache, GeodeSessionStateCache>());
+
+            services.AddSession(options =>
+            {
+                options.IdleTimeout = TimeSpan.FromSeconds(5);
+                options.Cookie.HttpOnly = true;
+                options.Cookie.IsEssential = true;
+            });
+
+            // Configure Method 1: Using extension method:
+            services.AddGeodeSessionStateCache(configuration =>
+            {
+                configuration.Host = "localhost";
+                configuration.Port = 10334;
+                configuration.RegionName = "geodeSessionState";
+            });
+
+            // Configure Method 2: Using appsettings.json:
+            //services.Configure<GeodeSessionStateCacheOptions>(
+            //    Configuration.GetSection("GeodeSessionStateCache"));
+
+            services.AddControllersWithViews();
+            services.AddRazorPages();
+        }
+
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        {
+            if (env.IsDevelopment())
+            {
+                app.UseDeveloperExceptionPage();
+            }
+            else
+            {
+                app.UseExceptionHandler("/Home/Error");
+                app.UseHsts();
+            }
+
+            app.UseStaticFiles();
+            app.UseRouting();
+            app.UseHttpContextItemsMiddleware();
+            app.UseSession();
+            app.UseEndpoints(endpoints =>
+            {
+                endpoints.MapDefaultControllerRoute();
+                endpoints.MapRazorPages();
+            });
+        }
+    }
+}
diff --git a/AspNetCore GeodeSession Sample/appsettings.Development.json b/AspNetCore GeodeSession Sample/appsettings.Development.json
new file mode 100644
index 0000000..0623a3f
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/appsettings.Development.json	
@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Debug",
+      "System": "Information",
+      "Microsoft": "Information"
+    }
+  }
+}
diff --git a/AspNetCore GeodeSession Sample/appsettings.Production.json b/AspNetCore GeodeSession Sample/appsettings.Production.json
new file mode 100644
index 0000000..8af1e1f
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/appsettings.Production.json	
@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Error",
+      "System": "Information",
+      "Microsoft": "Information"
+    }
+  }
+}
diff --git a/AspNetCore GeodeSession Sample/appsettings.json b/AspNetCore GeodeSession Sample/appsettings.json
new file mode 100644
index 0000000..956bfab
--- /dev/null
+++ b/AspNetCore GeodeSession Sample/appsettings.json	
@@ -0,0 +1,17 @@
+{
+  "Logging": {
+	"LogLevel": {
+	  "Default": "Warning"
+	}
+  },
+  "AllowedHosts": "*",
+  "AppSettings": {
+	"SiteTitle": "ASP.NET Core SessionState Sample App"
+  },
+
+  "GeodeSessionStateCache": {
+	"RegionName": "geodeSessionState",
+	"Host": "localhost",
+	"Port": 10334
+  }
+}