Search code examples
c#asp.net-mvcfiddlertempdata

TempData and Fiddler


public ActionResult Index()
{
    TempData["msg"] = "Test";
    return RedirectToAction("About");
}

public ActionResult About()
{
    var msg = TempData["msg"];
    return View();
}

A simple question. I am sure I will slap my forehead when I see the answer to it.

Navigating to the Index action in the browser results in a redirect to the About action and the TempData value is correct.

Why when I navigate to the Index action using the Fiddler composer it results in a redirect to the About action but the TempData value is lost and null?


Solution

  • I think the answer is found here (http://msdn.microsoft.com/en-us/library/ms178581(v=vs.100).aspx):

    "Sessions are identified by a unique identifier that can be read by using the SessionID property. When session state is enabled for an ASP.NET application, each request for a page in the application is examined for a SessionID value sent from the browser. If no SessionID value is supplied, ASP.NET starts a new session and the SessionID value for that session is sent to the browser with the response."

    When I add this line to the beginning of each Action:

    Debug.Write(string.Format("SessionId: {0}\r\n", HttpContext.Session.SessionID));
    

    I see that when you run from a browser the sessionid is the same. When run from the Fiddler composer they are different.

    Therefore, TempData is going to be reset using the default TempDataProvider (which stores the TempData in session state).