Using session to store the cart details instead of cookies.
This commit is contained in:
parent
6b0c2bb01f
commit
d29f24f4ad
|
|
@ -1,8 +1,8 @@
|
|||
REM copy the AspNet.Loader.dll to bin folder
|
||||
md bin
|
||||
md wwwroot\bin
|
||||
|
||||
SET ASPNETLOADER_PACKAGE_BASEPATH=%USERPROFILE%\.dotnet\packages\Microsoft.AspNet.Loader.IIS.Interop
|
||||
REM figure out the path of AspNet.Loader.dll
|
||||
FOR /F %%j IN ('dir /b /o:-d %ASPNETLOADER_PACKAGE_BASEPATH%\*') do (SET AspNetLoaderPath=%ASPNETLOADER_PACKAGE_BASEPATH%\%%j\tools\AspNet.Loader.dll)
|
||||
echo Found AspNetLoader.dll at %AspNetLoaderPath%. Copying to bin\
|
||||
copy %AspNetLoaderPath% bin\
|
||||
copy %AspNetLoaderPath% wwwroot\bin\
|
||||
|
|
@ -3,4 +3,4 @@ SET KRE_HOME=%USERPROFILE%\.kre\
|
|||
REM copy the AspNet.Loader.dll to the bin folder
|
||||
call CopyAspNetLoader.cmd
|
||||
|
||||
"%ProgramFiles(x86)%\iis Express\iisexpress.exe" /port:5001 /path:"%cd%"
|
||||
"%ProgramFiles(x86)%\iis Express\iisexpress.exe" /port:5001 /path:"%cd%\wwwroot"
|
||||
|
|
@ -147,22 +147,17 @@ namespace MusicStore.Models
|
|||
}
|
||||
|
||||
// We're using HttpContextBase to allow access to cookies.
|
||||
public string GetCartId(HttpContext context)
|
||||
private string GetCartId(HttpContext context)
|
||||
{
|
||||
var sessionCookie = context.Request.Cookies.Get("Session");
|
||||
string cartId = null;
|
||||
var cartId = context.Session.GetString("Session");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sessionCookie))
|
||||
if (cartId == null)
|
||||
{
|
||||
//A GUID to hold the cartId.
|
||||
cartId = Guid.NewGuid().ToString();
|
||||
|
||||
// Send cart Id as a cookie to the client.
|
||||
context.Response.Cookies.Append("Session", cartId);
|
||||
}
|
||||
else
|
||||
{
|
||||
cartId = sessionCookie;
|
||||
context.Session.SetString("Session", cartId);
|
||||
}
|
||||
|
||||
return cartId;
|
||||
|
|
|
|||
|
|
@ -87,6 +87,10 @@ namespace MusicStore
|
|||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
// Add session related services.
|
||||
services.AddCachingServices();
|
||||
services.AddSessionServices();
|
||||
|
||||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
|
|
@ -138,6 +142,9 @@ namespace MusicStore
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,10 @@ namespace MusicStore
|
|||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
// Add session related services.
|
||||
services.AddCachingServices();
|
||||
services.AddSessionServices();
|
||||
|
||||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
|
|
@ -97,6 +101,9 @@ namespace MusicStore
|
|||
});
|
||||
});
|
||||
|
||||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,10 @@ namespace MusicStore
|
|||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
// Add session related services.
|
||||
services.AddCachingServices();
|
||||
services.AddSessionServices();
|
||||
|
||||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
|
|
@ -104,6 +108,9 @@ namespace MusicStore
|
|||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,10 @@
|
|||
"Microsoft.AspNet.Security.Twitter": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
||||
"Microsoft.AspNet.Session": "1.0.0-*",
|
||||
"Microsoft.AspNet.SignalR.Server": "3.0.0-*",
|
||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
||||
"Microsoft.Framework.Cache.Memory": "1.0.0-*",
|
||||
"Microsoft.Framework.Cache.Distributed": "1.0.0-*", // For Session.
|
||||
"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-*",
|
||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
|
||||
"Microsoft.Framework.Logging.Console": "1.0.0-*"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -111,6 +111,10 @@ namespace MusicStore
|
|||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
// Add session related services.
|
||||
services.AddCachingServices();
|
||||
services.AddSessionServices();
|
||||
|
||||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
|
|
@ -118,6 +122,9 @@ namespace MusicStore
|
|||
});
|
||||
});
|
||||
|
||||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//To gracefully shutdown the server - Not for production scenarios
|
||||
app.Map("/shutdown", shutdown =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue