Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:01:08+00:00 2026-05-13T06:01:08+00:00

I wonder if anyone can help, i wish to save a variable globally for

  • 0

I wonder if anyone can help, i wish to save a variable globally for the current user on the current page, i thought Sessions are bad in mvc??

I should give an example of what i am doing. Basically i have a controller and it enters (Action = Index) and i check

Request.UrlReferrer

And if it contains a value that means it arrived from another place i.e. Google for example. And i write the information to a log. Now at this stage in the controller all is fine.

But later in my page i wish to recall a method in the controller (using jquery and ajax) to process some more tracking but remembering i am still in the same page, i use

 Request.UrlReferrer

but at this stage its always going to be the name of the page as the referrer is the page that initiated the ajax call and “NOT” google. Ok so it appears i need to save the value or UrlReferrer to a global variable/per user so that when i reenter my controller i can check this SAVED variable rather thatn Request.UrlReferrer.

Does anyone know the easiest way to do this?

here is an example of my page

public ActionResult Index()
    {
        // Process tracking - Initial entry
        string ip = Request.UserHostAddress.ToString();
        string referrer = null;

        if (Request.UrlReferrer !=null)
            referrer = Request.UrlReferrer.ToString();

        // WRITE THE LOGS HERE!!!!

        return View();
    }

    public ActionResult ProcessTracking()
    {
        // Reprocess tracking
        // BUt can't use Request.UrlReferrer as it returns my calling page and not google
        // for example




        //string ip = Request.UserHostAddress.ToString();
        //string referrer = null;

        //if (Request.UrlReferrer != null)
        //    referrer = Request.UrlReferrer.ToString();

        //return View();
    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:01:08+00:00Added an answer on May 13, 2026 at 6:01 am

    You should store the value in TempData. The whole purpose of TempData is to persist information between controller calls. As of MVC 2 Beta the value will stay there until it is read.

    public ActionResult Index()
    {        
    // Process tracking - Initial entry        
    string ip = Request.UserHostAddress.ToString();        
    string referrer = null;        
    if (Request.UrlReferrer !=null)            
    referrer = Request.UrlReferrer.ToString(); 
    TempData["referrer"] = referrer;   
    // WRITE THE LOGS HERE!!!!        
    return View();    
    }    
    
    public ActionResult ProcessTracking()    
    {        
    // Reprocess tracking        
    // BUt can't use Request.UrlReferrer as it returns my calling page and not google        
    // for example        
    string ip = Request.UserHostAddress.ToString();        
    string referrer = TempData["referrer"];        
    //continue processing here   
    return View();    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if anyone can provide me with the regular expressions needed to parse
As you can see below, I am checking to see if the current user
I wonder if anyone uses commercial/free java obfuscators on his own commercial product. I
I wonder if anyone could suggest the best way of looping through all the
I wonder if anyone here has any experience with mercurial running on Ubuntu? I've
I just wonder if anyone knows or made a wrapper around Active Directory to
As someone who hasn't used either technology on real-world projects I wonder if anyone
Has anyone used TUDBC ? This looks interesting, but I wonder how valuable it
Wonder what the difference between: static PROCESSWALK pProcess32First=(PROCESSWALK)GetProcAddress(hKernel,Process32First); ... pProcess32First(...); what is hKernel? Look
I wonder if someone knows if there is a pre-made solution for this: I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.