MVC Controller State Managment
-
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
-
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
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
-
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
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