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/08/26 20:33:40 UTC

[geode-native] branch develop updated: GEODE-9464: Add Asp.Net Core session state sample application (#856)

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

mmartell pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 597ab21  GEODE-9464: Add Asp.Net Core session state sample application  (#856)
597ab21 is described below

commit 597ab211c7182ceab8942816f9adbe49d3af3b8f
Author: Michael Martell <mm...@pivotal.io>
AuthorDate: Thu Aug 26 13:33:36 2021 -0700

    GEODE-9464: Add Asp.Net Core session state sample application  (#856)
    
    * Add AspNetCore GeodeSession Sample
    * Create region for sessionState in startserver
    * Add Apache license header
---
 .../AspNetCore GeodeSession Sample.csproj          |  13 ++
 .../AspNetCore GeodeSession Sample.csproj.user     |   6 +
 .../Extensions/SessionExtensions.cs                |  53 +++++
 .../Middleware/HttpContextItemsMiddleware.cs       |  45 ++++
 .../Models/BasicAuthInitialize.cs                  |  47 ++++
 .../Models/ErrorViewModel.cs                       |  27 +++
 .../Pages/Error.cshtml                             |  42 ++++
 .../Pages/Error.cshtml.cs                          |  36 ++++
 .../Pages/Index.cshtml                             |  99 +++++++++
 .../Pages/Index.cshtml.cs                          |  62 ++++++
 .../Pages/Shared/_Layout.cshtml                    | 237 +++++++++++++++++++++
 .../Pages/_ViewImports.cshtml                      |  19 ++
 .../Pages/_ViewStart.cshtml                        |  19 ++
 netcore/AspNetCore GeodeSession Sample/Program.cs  |  29 +++
 .../Properties/launchSettings.json                 |  28 +++
 netcore/AspNetCore GeodeSession Sample/README.md   |  58 +++++
 netcore/AspNetCore GeodeSession Sample/Startup.cs  |  79 +++++++
 .../appsettings.Development.json                   |   9 +
 .../appsettings.Production.json                    |   9 +
 .../appsettings.json                               |  17 ++
 netcore/geode-dotnet-core.sln                      |   7 +
 netcore/scripts/startserver.ps1                    |   8 +-
 netcore/scripts/startserver.sh                     |   4 +-
 23 files changed, 948 insertions(+), 5 deletions(-)

diff --git a/netcore/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj b/netcore/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj
new file mode 100644
index 0000000..fb587cb
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj	
@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <Platforms>x64</Platforms>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\NetCore.Session\NetCore.Session.csproj" />
+  </ItemGroup>
+
+
+</Project>
diff --git a/netcore/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj.user b/netcore/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj.user
new file mode 100644
index 0000000..9dd7dfa
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/AspNetCore GeodeSession Sample.csproj.user	
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <ActiveDebugProfile>IIS Express</ActiveDebugProfile>
+  </PropertyGroup>
+</Project>
diff --git a/netcore/AspNetCore GeodeSession Sample/Extensions/SessionExtensions.cs b/netcore/AspNetCore GeodeSession Sample/Extensions/SessionExtensions.cs
new file mode 100644
index 0000000..367ee56
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Extensions/SessionExtensions.cs	
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+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;
+    }
+  }
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/Middleware/HttpContextItemsMiddleware.cs b/netcore/AspNetCore GeodeSession Sample/Middleware/HttpContextItemsMiddleware.cs
new file mode 100644
index 0000000..8b7ca4b
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Middleware/HttpContextItemsMiddleware.cs	
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+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/netcore/AspNetCore GeodeSession Sample/Models/BasicAuthInitialize.cs b/netcore/AspNetCore GeodeSession Sample/Models/BasicAuthInitialize.cs
new file mode 100644
index 0000000..067d41d
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Models/BasicAuthInitialize.cs	
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+using Apache.Geode.Client;
+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;
+    }
+  }
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/Models/ErrorViewModel.cs b/netcore/AspNetCore GeodeSession Sample/Models/ErrorViewModel.cs
new file mode 100644
index 0000000..49f70ef
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Models/ErrorViewModel.cs	
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace SessionSample.Models
+{
+  public class ErrorViewModel
+  {
+  }
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/Pages/Error.cshtml b/netcore/AspNetCore GeodeSession Sample/Pages/Error.cshtml
new file mode 100644
index 0000000..7e0919b
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/Error.cshtml	
@@ -0,0 +1,42 @@
+@*
+ * 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
+@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/netcore/AspNetCore GeodeSession Sample/Pages/Error.cshtml.cs b/netcore/AspNetCore GeodeSession Sample/Pages/Error.cshtml.cs
new file mode 100644
index 0000000..b6245b6
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/Error.cshtml.cs	
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+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/netcore/AspNetCore GeodeSession Sample/Pages/Index.cshtml b/netcore/AspNetCore GeodeSession Sample/Pages/Index.cshtml
new file mode 100644
index 0000000..47bcf75
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/Index.cshtml	
@@ -0,0 +1,99 @@
+@*
+  * 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.&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/netcore/AspNetCore GeodeSession Sample/Pages/Index.cshtml.cs b/netcore/AspNetCore GeodeSession Sample/Pages/Index.cshtml.cs
new file mode 100644
index 0000000..723979e
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/Index.cshtml.cs	
@@ -0,0 +1,62 @@
+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/netcore/AspNetCore GeodeSession Sample/Pages/Shared/_Layout.cshtml b/netcore/AspNetCore GeodeSession Sample/Pages/Shared/_Layout.cshtml
new file mode 100644
index 0000000..4465c65
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/Shared/_Layout.cshtml	
@@ -0,0 +1,237 @@
+@*
+  * 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.
+*@
+<!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 {
+	font-family: inherit;
+	font-size: inherit;
+	line-height: inherit;
+	}
+
+	a {
+	color: #337ab7;
+	text-decoration: none;
+	}
+
+	h1, h2, h3, h4 {
+	font-family: inherit;
+	font-weight: 500;
+	line-height: 1.1;
+	color: inherit;
+	margin-top: 20px;
+	margin-bottom: 10px;
+	}
+
+	h3 {
+	font-size: 16px;
+	}
+
+	h4 {
+	font-size: 18px;
+	}
+
+	p {
+	margin: 0 0 10px;
+	}
+
+	ol {
+	margin-top: 0;
+	margin-bottom: 10px;
+	}
+
+	code, pre {
+	font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
+	}
+
+	code {
+	padding: 2px 4px;
+	font-size: 90%;
+	color: #c7254e;
+	background-color: #f9f2f4;
+	border-radius: 4px;
+	}
+
+	pre {
+	display: block;
+	padding: 9.5px;
+	margin: 0 0 10px;
+	font-size: 13px;
+	line-height: 1.42857143;
+	color: #333;
+	word-break: break-all;
+	word-wrap: break-word;
+	background-color: #f5f5f5;
+	border: 1px solid #ccc;
+	-radius: 4px;
+	}
+
+	pre code {
+	padding: 0;
+	font-size: inherit;
+	color: inherit;
+	white-space: pre-wrap;
+	background-color: transparent;
+	border-radius: 0;
+	}
+
+	.container {
+	padding-right: 15px;
+	padding-left: 15px;
+	margin-right: auto;
+	margin-left: auto;
+	}
+
+	.container {
+	width: 800px;
+	}
+
+	.btn {
+	display: inline-block;
+	padding: 6px 12px;
+	margin-bottom: 0;
+	font-size: 14px;
+	font-weight: normal;
+	line-height: 1.42857143;
+	text-align: center;
+	white-space: nowrap;
+	vertical-align: middle;
+	background-image: none;
+	border: 1px solid transparent;
+	border-radius: 4px;
+	;
+	color: #fff;
+	background-color: green;
+	border-color: gray;
+	float: right
+	}
+
+	.panel {
+	margin-bottom: 20px;
+	background-color: #fff;
+	border: 1px solid transparent;
+	border-radius: 4px;
+	box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
+	}
+
+	.panel-body {
+	padding: 15px;
+	}
+
+	.panel-heading {
+	padding: 10px 15px;
+	border-bottom: 1px solid transparent;
+	border-top-left-radius: 3px;
+	border-top-right-radius: 3px;
+	}
+
+	.panel-title {
+	margin-top: 0;
+	margin-bottom: 0;
+	font-size: 16px;
+	color: inherit;
+	}
+
+	.panel-default {
+	border-color: #ddd;
+	}
+
+	.panel-default > .panel-heading {
+	color: #333;
+	background-color: #f5f5f5;
+	border-color: #ddd;
+	}
+
+	.clearfix:before, .clearfix:after, .container:before, .container:after, .panel-body:before, .panel-body:after {
+	display: table;
+	content: " ";
+	}
+
+	.clearfix:after, .container:after, .panel-body:after {
+	clear: both;
+	}
+
+	.body-content {
+	padding-left: 15px;
+	padding-right: 15px;
+	}
+
+	.panel-body {
+	font-size: 16px;
+	}
+  </style>
+</head>
+<body>
+  <div class="container body-content">
+    @RenderBody()
+  </div>
+</body>
+</html>
diff --git a/netcore/AspNetCore GeodeSession Sample/Pages/_ViewImports.cshtml b/netcore/AspNetCore GeodeSession Sample/Pages/_ViewImports.cshtml
new file mode 100644
index 0000000..7bf76d4
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/_ViewImports.cshtml	
@@ -0,0 +1,19 @@
+@*
+  * 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.
+*@
+@using SessionSample
+@namespace SessionSample.Pages
+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
diff --git a/netcore/AspNetCore GeodeSession Sample/Pages/_ViewStart.cshtml b/netcore/AspNetCore GeodeSession Sample/Pages/_ViewStart.cshtml
new file mode 100644
index 0000000..7e03e6d
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Pages/_ViewStart.cshtml	
@@ -0,0 +1,19 @@
+@*
+  * 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.
+*@
+@{
+  Layout = "_Layout";
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/Program.cs b/netcore/AspNetCore GeodeSession Sample/Program.cs
new file mode 100644
index 0000000..4495aab
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Program.cs	
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+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/netcore/AspNetCore GeodeSession Sample/Properties/launchSettings.json b/netcore/AspNetCore GeodeSession Sample/Properties/launchSettings.json
new file mode 100644
index 0000000..5fdcaca
--- /dev/null
+++ b/netcore/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"
+	}
+  }
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/README.md b/netcore/AspNetCore GeodeSession Sample/README.md
new file mode 100644
index 0000000..38b0a9b
--- /dev/null
+++ b/netcore/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/netcore/AspNetCore GeodeSession Sample/Startup.cs b/netcore/AspNetCore GeodeSession Sample/Startup.cs
new file mode 100644
index 0000000..cb9ada2
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/Startup.cs	
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+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/netcore/AspNetCore GeodeSession Sample/appsettings.Development.json b/netcore/AspNetCore GeodeSession Sample/appsettings.Development.json
new file mode 100644
index 0000000..0623a3f
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/appsettings.Development.json	
@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Debug",
+      "System": "Information",
+      "Microsoft": "Information"
+    }
+  }
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/appsettings.Production.json b/netcore/AspNetCore GeodeSession Sample/appsettings.Production.json
new file mode 100644
index 0000000..8af1e1f
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/appsettings.Production.json	
@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Error",
+      "System": "Information",
+      "Microsoft": "Information"
+    }
+  }
+}
diff --git a/netcore/AspNetCore GeodeSession Sample/appsettings.json b/netcore/AspNetCore GeodeSession Sample/appsettings.json
new file mode 100644
index 0000000..8205b26
--- /dev/null
+++ b/netcore/AspNetCore GeodeSession Sample/appsettings.json	
@@ -0,0 +1,17 @@
+{
+  "Logging": {
+	"LogLevel": {
+	  "Default": "Warning"
+	}
+  },
+  "AllowedHosts": "*",
+  "AppSettings": {
+	"SiteTitle": "ASP.NET Core Geode SessionState Sample App"
+  },
+
+  "GeodeSessionStateCache": {
+	"RegionName": "geodeSessionState",
+	"Host": "localhost",
+	"Port": 10334
+  }
+}
diff --git a/netcore/geode-dotnet-core.sln b/netcore/geode-dotnet-core.sln
index 164413c..d44f076 100644
--- a/netcore/geode-dotnet-core.sln
+++ b/netcore/geode-dotnet-core.sln
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Session", "NetCore.
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Session.IntegrationTests", "NetCore.Session.IntegrationTests\NetCore.Session.IntegrationTests.csproj", "{94D2CD59-A5F3-4504-BF01-0A3B95CE12B5}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore GeodeSession Sample", "AspNetCore GeodeSession Sample\AspNetCore GeodeSession Sample.csproj", "{4E830BC8-D1CA-40AF-9C9C-D15E193C6585}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|x64 = Debug|x64
@@ -35,6 +37,10 @@ Global
 		{94D2CD59-A5F3-4504-BF01-0A3B95CE12B5}.Debug|x64.Build.0 = Debug|x64
 		{94D2CD59-A5F3-4504-BF01-0A3B95CE12B5}.Release|x64.ActiveCfg = Release|x64
 		{94D2CD59-A5F3-4504-BF01-0A3B95CE12B5}.Release|x64.Build.0 = Release|x64
+		{4E830BC8-D1CA-40AF-9C9C-D15E193C6585}.Debug|x64.ActiveCfg = Debug|x64
+		{4E830BC8-D1CA-40AF-9C9C-D15E193C6585}.Debug|x64.Build.0 = Debug|x64
+		{4E830BC8-D1CA-40AF-9C9C-D15E193C6585}.Release|x64.ActiveCfg = Release|x64
+		{4E830BC8-D1CA-40AF-9C9C-D15E193C6585}.Release|x64.Build.0 = Release|x64
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -42,6 +48,7 @@ Global
 	GlobalSection(NestedProjects) = preSolution
 		{B88C58EB-B144-403B-85F7-7A5B45E643E3} = {520C96EC-F929-4365-8D78-CC5785419B62}
 		{94D2CD59-A5F3-4504-BF01-0A3B95CE12B5} = {520C96EC-F929-4365-8D78-CC5785419B62}
+		{4E830BC8-D1CA-40AF-9C9C-D15E193C6585} = {520C96EC-F929-4365-8D78-CC5785419B62}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {B30A49F0-1C96-4D6C-A222-0088B1D7FBBE}
diff --git a/netcore/scripts/startserver.ps1 b/netcore/scripts/startserver.ps1
index 704be3e..2321418 100644
--- a/netcore/scripts/startserver.ps1
+++ b/netcore/scripts/startserver.ps1
@@ -52,14 +52,16 @@ if ($GFSH_PATH -ne "")
    $expression = "$GFSH_PATH " + `
         "-e 'start locator --name=locator --port=10334 --http-service-port=6060 --J=-Dgemfire.jmx-manager-port=1099' " + `
         "-e 'start server --name=server --server-port=0' " + `
-        "-e 'create region --name=exampleRegion --type=PARTITION'";
+        "-e 'create region --name=exampleRegion --type=PARTITION' " + `
+        "-e 'create region --name=geodeSessionState --type=PARTITION'";
    Invoke-Expression $expression
 
    $expression = "$GFSH_PATH " + `
         "-e 'start locator --name=auth_locator $AUTH_LOCATOR_OPTS --port=10335 --http-service-port=7070 --J=-Dgemfire.jmx-manager-port=2099' " + `
         "-e 'connect --locator=localhost[10335] --user=server --password=server' " + `
         "-e 'start server --name=auth_server $AUTH_OPTS --server-port=0' " + `
-        "-e 'create region --name=authExampleRegion --type=PARTITION'";
+        "-e 'create region --name=authExampleRegion --type=PARTITION' " + `
+        "-e 'create region --name=authGeodeSessionState --type=PARTITION'";
    Invoke-Expression $expression
 }
- 
+ 
\ No newline at end of file
diff --git a/netcore/scripts/startserver.sh b/netcore/scripts/startserver.sh
index 10d8283..3444d9f 100644
--- a/netcore/scripts/startserver.sh
+++ b/netcore/scripts/startserver.sh
@@ -43,6 +43,6 @@ AUTH_OPTS="${AUTH_OPTS} --classpath=${NETCORE_JAVA_BUILD_HOME}/example.jar"
 AUTH_LOCATOR_OPTS="${AUTH_OPTS} --J=-Dgemfire.security-manager=javaobject.SimpleSecurityManager" 
 
 
-$GFSH_PATH  -e "start locator --name=locator --port=10334 --http-service-port=6060 --J=-Dgemfire.jmx-manager-port=1099" -e "start server --name=server --server-port=0"  -e "create region --name=exampleRegion --type=PARTITION"
+$GFSH_PATH  -e "start locator --name=locator --port=10334 --http-service-port=6060 --J=-Dgemfire.jmx-manager-port=1099" -e "start server --name=server --server-port=0"  -e "create region --name=exampleRegion --type=PARTITION" -e "create region --name=geodeSessionState --type=PARTITION"
 
-$GFSH_PATH  -e "start locator --name=auth_locator ${AUTH_LOCATOR_OPTS} --port=10335 --http-service-port=7070 --J=-Dgemfire.jmx-manager-port=2099" -e "connect --locator=localhost[10335] --user=server --password=server" -e "start server --name=auth_server ${AUTH_OPTS} --server-port=0"  -e "create region --name=authExampleRegion --type=PARTITION"
+$GFSH_PATH  -e "start locator --name=auth_locator ${AUTH_LOCATOR_OPTS} --port=10335 --http-service-port=7070 --J=-Dgemfire.jmx-manager-port=2099" -e "connect --locator=localhost[10335] --user=server --password=server" -e "start server --name=auth_server ${AUTH_OPTS} --server-port=0"  -e "create region --name=authExampleRegion --type=PARTITION" -e "create region --name=authGeodeSessionState --type=PARTITION"