0

I have an ASP.NET Core 2 web app. It's actually an implementation of Identity Server 4, but I don't believe that is related to my issue. I have a controller with an action that represents the callback from an external OAuth service. I've stripped out all the handler logic, leaving just this:

[HttpGet]
[AllowAnonymous]
[Route("challenge/callback")]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
    TempData["Test"] = "hello world";

    return RedirectToAction("Index", "App", new { path = "oauth-register" });
}

You can see I'm setting some tempt data and redirecting. The view it redirects to simply iterates the TempData collection and renders each key/value.

The application is using a default implementation of TempData, so no extra providers registered or anything.

I now perform the following 2 actions:

  1. I visit this challenge/callback URL in my browser and confirm I'm redirected as expected and my temp data "hello world" is written to the screen.
  2. I now follow my application's sign in path, get redirected to the external provider, sign in and get redirected back to my application. Here the debugger passes through the above action and again performs the same redirect. But this time the TempData collection is empty and nothing is written out by the target view.

I cannot understand this because surely as far as my application is concerned both these actions are identical. They are both GET requests for the same endpoint. Does TempData behave different based on referer or other request-specific variable?

I hope someone can put me out of my misery here!

Tom Troughton
  • 3,941
  • 2
  • 37
  • 77
  • I think this SO link may help. https://stackoverflow.com/questions/31332924/life-time-of-viewbag-tempdata-viewdata-and-session. I think the issue is that you redirect more than once in the sign-in process. – Andrew Jun 13 '18 at 15:29
  • I'm not sure. Like I say I can see my debugger in the action method that sets the `TempData` and redirects, then in the redirect target `TempData` is already empty. There is no additional redirect between these. Should it matter that my arrival at the first action is itself a redirect? – Tom Troughton Jun 13 '18 at 15:43

0 Answers0