Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. MVC Controller State Managment

MVC Controller State Managment

Scheduled Pinned Locked Moved .NET (Core and Framework)
databaseasp-netarchitecturehelptutorial
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kunal Mandloi
    wrote on last edited by
    #1

    I am working on Webhooks Concept. Since Webhooks act like an trigger. It will be firing an event like Update or Insert takes place. Its a MVC application and I have two Controller Home and Webhook Controller. I am passing argument through Query String on Home controller. I have tried Session,TempData, Cookies for passing variable from home to Webhooks HttpContext.Session.SetString("UserName", Request.Query["UserName"].ToString());

    and getting session value on webhook controller

    HttpContext.Session.GetString("UserName");

    Also tried the same for TempData

    Issue is On webbooks Controller its coming null.

    I need to store parameter (User Name ,password) and reused the same for database related operation

    Kindly guide

    Richard DeemingR K 2 Replies Last reply
    0
    • K Kunal Mandloi

      I am working on Webhooks Concept. Since Webhooks act like an trigger. It will be firing an event like Update or Insert takes place. Its a MVC application and I have two Controller Home and Webhook Controller. I am passing argument through Query String on Home controller. I have tried Session,TempData, Cookies for passing variable from home to Webhooks HttpContext.Session.SetString("UserName", Request.Query["UserName"].ToString());

      and getting session value on webhook controller

      HttpContext.Session.GetString("UserName");

      Also tried the same for TempData

      Issue is On webbooks Controller its coming null.

      I need to store parameter (User Name ,password) and reused the same for database related operation

      Kindly guide

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Session and TempData both rely on cookies to identify the requesting browser. They have a limited life-span, so data you store in them won't hang around forever. If the data isn't available in the web-hook request, that means either the session has timed out between the initial request and the hook request; or the hook request was made from a different process than the initial request, or using a tool which doesn't store the cookies you set. You will need to find a different solution. Since you haven't provided any details of what you're actually trying to do, we can't offer any suggestions. NB: Storing credentials in memory is not a good idea.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • K Kunal Mandloi

        I am working on Webhooks Concept. Since Webhooks act like an trigger. It will be firing an event like Update or Insert takes place. Its a MVC application and I have two Controller Home and Webhook Controller. I am passing argument through Query String on Home controller. I have tried Session,TempData, Cookies for passing variable from home to Webhooks HttpContext.Session.SetString("UserName", Request.Query["UserName"].ToString());

        and getting session value on webhook controller

        HttpContext.Session.GetString("UserName");

        Also tried the same for TempData

        Issue is On webbooks Controller its coming null.

        I need to store parameter (User Name ,password) and reused the same for database related operation

        Kindly guide

        K Offline
        K Offline
        Kunal Mandloi
        wrote on last edited by
        #3

        This is my home controller.... Where I am passing value in query string.......

        using IdentityModel.Client;
        using Microsoft.AspNetCore.Http;
        using Microsoft.AspNetCore.Mvc;
        using Microsoft.AspNetCore.Mvc.ModelBinding;
        using Newtonsoft.Json;
        using NLog;
        using System;
        using System.Collections.Generic;
        using System.Net;
        using System.Net.Http;
        using Newtonsoft;
        using System.Text.RegularExpressions;
        using System.Net.Http.Headers;
        using System.Diagnostics;
        using Newtonsoft.Json.Linq;
        using System.IO;
        using Microsoft.Extensions.Configuration;
        using Microsoft.Extensions.Options;

        namespace MYApp.Controllers
        {

        public class HomeController : Controller
        {
           
           
           
            Logger logger = LogManager.GetCurrentClassLogger();
            private string clientId = "";
            private string clientSecret = "";
            
            private ModelStateDictionary ValidationMessages { get; set; }
        
             
        
            public class UserInfo
        
            {
                public string Addresses { get; set; }
                public string OriginatorNo { get; set; }
        
                public string OriginatorName { get; set; }
        
                public string ContactName { get; set; }
        
                public string FirstName { get; set; }
                public string LastName { get; set; }
                public string Email { get; set; }
        
            }
         
           
            public IActionResult Index()
            {
              
                try
                {
        
                    //int a = 0;
                    //int b = 1;
                    //int c = b / a;
              
        
                string strUrl = "https://url";
              
        
                    if (Request.Query\["UserName"\].ToString() != string.Empty && Request.Query\["Password"\] != string.Empty)
                    {
        
                      
                        HttpContext.Session.SetString("UserName", Request.Query\["UserName"\].ToString());
                       
                        HttpContext.Session.SetString("Password", Request.Query\["strPassword"\].ToString());
                       
                    }
                    
                  
        
        
                }
                catch (Exception ex)
                {
                    
        
                }
        
        
            }
        
           
            public class ContactPerson
            {
                public string FirstName { get; set; }
                public string LastName { get; set; }
                public string Email { get; set; }
                public string IncludeInEmails { get; set; }
            }
          
            public IActionRes
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups