Why does ASP.NET TempData not work when changing Web.config?

I have a function in my file Global.asax.csthat, if necessary, adds a couple of changes to the file Web.config. The file is saved using:

config.Save(ConfigurationSaveMode.Modified);

I recently discovered that it TempDatadidn’t work for my application: it turned out to be empty in the next request. My MCVE :

public ActionResult Foo()
{
  TempData["error"] = "testing error passing";
  return RedirectToAction("Bar");
}

public ActionResult Bar()
{
  throw new Exception(TempData["error"] as string);
}

I added that to mine HomeController, and the visit /Home/Foowill be redirected to /Home/Bar. However, if the above line is config.Saveactive, I get:

Server Error in '/' Application.
Exception of type 'System.Exception' was thrown.

But if I comment on this line, I get:

Server Error in '/' Application.
test error passing

as I originally expected.

( , , , , , , .)

, ?

0
2

:

, web.config?

, ASP.NET( IIS) . web.config - . -

IIS reset AppDomain , web.config , , TempData, , .

config.Save ​​ , :

throw new Exception(TempData["error"] as string);

TempData["error"]:

throw new Exception(null);

as null, , Exception , .

config.Save , web.config, AppDomain , TempData .

:

  • IIS.
  • = > [ ] = > .
  • "" Disable Recycling for Configuration Changes (DisallowRotationOnConfigChange) True.

: ASP.NET web.config?

+3

TempData , , - InProc, , AppDomain .

, - , IIS , , -.

, .

web.config , - , , , -

+1

Source: https://habr.com/ru/post/1654038/


All Articles