Answers for "use session in dotnet core mvc"

C#
2

.net core session

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, 773);
        }

        var name = HttpContext.Session.GetString(SessionKeyName);
        var age = HttpContext.Session.GetInt32(SessionKeyAge);
Posted by: Guest on June-05-2020
0

Using Session in ASP.NET MVC

private void btnSubmit_Click(object sender, System.EventArgs e)
{ if(IsValid)
  { // Set the Session value.
    Session[txtName.Text] = txtValue.Text;
    // Read and display the value we just set
    lblResult.Text = "The value of <b>" +
	 txtName.Text + "</b> in the Session object is <b>" +
	 Session[txtName.Text].ToString() + "</b>"; } }
Posted by: Guest on May-04-2021

C# Answers by Framework

Browse Popular Code Answers by Language