Asp.Net core Tempdata and redirecttoaction not working

TempData uses Session, which itself uses IDistributedCache. IDistributedCache doesn’t have the capability to accept objects or to serialize objects. As a result, you need to do this yourself, i.e.: TempData[“PopupMessages”] = JsonConvert.SerializeObject(_popupMessages); Then, of course, after redirecting, you’ll need to deserialize it back into the object you need: TempData[“PopupMessages”] = JsonConvert.DeserializeObject<List<PopupMessage>>(TempData[“PopupMessages”].ToString());

When to use TempData vs Session in ASP.Net MVC

TempData is session, so they’re not entirely different. However, the distinction is easy to understand, because TempData is for redirects, and redirects only. So when you set some message in TempData and then redirect, you are using TempData correctly. However, using Session for any kind of security is extremely dangerous. Session and Membership are entirely … Read more

How can I disable session state in ASP.NET MVC?

You could make your own ControllerFactory and DummyTempDataProvider. Something like this: public class NoSessionControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(Type controllerType) { var controller = base.GetControllerInstance(controllerType); ((Controller) controller).TempDataProvider = new DummyTempDataProvider(); return controller; } } public class DummyTempDataProvider : ITempDataProvider { public IDictionary<string, object> LoadTempData(ControllerContext controllerContext) { return new Dictionary<string, object>(); } public void … Read more

Store complex object in TempData

You can create the extension methods like this: public static class TempDataExtensions { public static void Put<T>(this ITempDataDictionary tempData, string key, T value) where T : class { tempData[key] = JsonConvert.SerializeObject(value); } public static T Get<T>(this ITempDataDictionary tempData, string key) where T : class { object o; tempData.TryGetValue(key, out o); return o == null ? … Read more

TempData keep() vs peek()

When an object in a TempDataDictionary is read, it will be marked for deletion at the end of that request. That means if you put something on TempData like TempData[“value”] = “someValueForNextRequest”; And on another request you access it, the value will be there but as soon as you read it, the value will be … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)