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 736887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:39:24+00:00 2026-05-14T07:39:24+00:00

If I redirect to a new page passing TempData to initialise the page it

  • 0

If I redirect to a new page passing TempData to initialise the page it works fine, however if the user presses the refresh button in their browser the TempData is no-longer available.
Given this, is there any situation where TempData could be used reliably?
Or any way to remove or mitigate the problem of users refreshing?

  • 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-14T07:39:24+00:00Added an answer on May 14, 2026 at 7:39 am

    In MVC 1, yes, temp data is lost after the next request after you store a key.

    With MVC 2 however, the temp data is lost after the first attempt to access it.

    You can always use Session, which TempData uses anyway, to solve the temp data loss issue your having.

    From the MVC 2 Beta Release Notes:

    TempDataDictionary Improvements

    The behavior of the TempDataDictionary
    class has been changed slightly to
    address scenarios where temp data was
    either removed prematurely or
    persisted longer than necessary. For
    example, in cases where temp data was
    read in the same request in which it
    was set, the temp data was persisting
    for the next request even though the
    intent was to remove it. In other
    cases, temp data was not persisted
    across multiple consecutive redirects.

    To address these scenarios, the
    TempDataDictionary class was changed
    so that all the keys survive
    indefinitely until the key is read
    from the TempDataDictionary object.
    The Keep method was added to
    TempDataDictionary to let you indicate
    that the value should not be removed
    after reading. The
    RedirectToActionResult is an example
    where the Keep method is called in
    order to retain all the keys for the
    next request.

    You can also look directly in the MVC 2 source to see these changes:

    MVC 1:

      public object this[string key] {
            get {
                object value;
                if (TryGetValue(key, out value)) {
                    return value;
                }
                return null;
            }
            set {
                _data[key] = value;
                _modifiedKeys.Add(key);
            }
        }
    

    MVC 2:

       public object this[string key] {
            get {
                object value;
                if (TryGetValue(key, out value)) {
                    _initialKeys.Remove(key);
                    return value;
                }
                return null;
            }
            set {
                _data[key] = value;
                _initialKeys.Add(key);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I redirect the user to the login page when user click log out however
How can I pass user control properties to the page AND make these properties
I am new to javascript programming. I have a page on which if Back
I am using a flash module for site navigation (Freemind flash browser). However, I'm
I'm trying to redirect all requests to my domain to another domain using mod_rewrite
How do you redirect HTTPS to HTTP?. That is, the opposite of what (seemingly)
I'd like to redirect the stdout of process proc1 to two processes proc2 and
How can I redirect the response to an IFrame?
I'm trying to redirect requests for a wildcard domain to a sub-directory. ie. something.blah.example.com
When I call Response.Redirect(someUrl) I get the following HttpException: Cannot redirect after HTTP headers

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.