Use standard object/json for User Data
This commit is contained in:
@ -5,13 +5,13 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace StateJobsNYSubmit.Pages
|
namespace StateJobsNYSubmit.Pages
|
||||||
{
|
{
|
||||||
public class IndexModel : PageModel
|
public class IndexModel : PageModel
|
||||||
{
|
{
|
||||||
private readonly ILogger<IndexModel> _logger;
|
private readonly ILogger<IndexModel> _logger;
|
||||||
public int counter = 1;
|
|
||||||
private PrivateData p = new PrivateData();
|
private PrivateData p = new PrivateData();
|
||||||
public IndexModel(ILogger<IndexModel> logger)
|
public IndexModel(ILogger<IndexModel> logger)
|
||||||
{
|
{
|
||||||
@ -20,14 +20,16 @@ namespace StateJobsNYSubmit.Pages
|
|||||||
|
|
||||||
public void OnGet()
|
public void OnGet()
|
||||||
{
|
{
|
||||||
|
UserData userData = new UserData();
|
||||||
|
userData.visitCounter = 1;
|
||||||
string cookieValue = Request.Cookies["PrivateData"];
|
string cookieValue = Request.Cookies["PrivateData"];
|
||||||
if (cookieValue != null) {
|
if (cookieValue != null) {
|
||||||
string test = p.DecryptString(cookieValue);
|
string test = p.DecryptString(cookieValue);
|
||||||
counter = Int32.Parse(test);
|
userData = JsonConvert.DeserializeObject<UserData>(test);
|
||||||
counter++;
|
userData.visitCounter++;
|
||||||
}
|
}
|
||||||
Response.Cookies.Append("PrivateData", p.EncryptString($"{counter}"));
|
Response.Cookies.Append("PrivateData", p.EncryptString(JsonConvert.SerializeObject(userData)));
|
||||||
Console.WriteLine($"Value of counter: {counter}");
|
Console.WriteLine($"Value of counter: {userData.visitCounter}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
UserData.cs
Normal file
12
UserData.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// UserData myDeserializedClass = JsonConvert.DeserializeObject<UserData>(myJsonResponse);
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
public class UserData
|
||||||
|
{
|
||||||
|
public string email { get; set; }
|
||||||
|
public string smtpHost { get; set; }
|
||||||
|
public List<string> skillOptions { get; set; }
|
||||||
|
public string identifier { get; set; }
|
||||||
|
public int visitCounter { get; set;}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user