Skip to content

fukasawah/sandbox-aspnet-mvc-tempdata-enum

Repository files navigation

sandbox-aspnet-mvc-tempdata-enum

  • .NET Core 3.1.x
  • ASP.NET 3.1.23

Steps to reproduce

image

Click "OK" link.

image

  • Set State=OK and redirect to Index page
  • Show State=OK (Cookies should be deleted here, but they are not.)

Click "Reload" link. (or F5)

image

  • Expect: State=VIEW
  • Actual: State=OK

Why undelete enum value on TempData?

The code here does not take enum into account.

https://github.com/dotnet/aspnetcore/blob/v3.1.23/src/Mvc/Mvc.ViewFeatures/src/Filters/SaveTempDataPropertyFilterBase.cs#L55

OriginalValue derived from Cookie is handled as int, but newValue is handled as Enum since it is derived from Property.

See Variables in the following debugger for type differences

eg.) string Message

image

eg.) enum State

image

Therefore, newValue.Equals(OriginalValue) becomes (1.Equals((Enum)1) and returns false. Then tempData[key] = newValue is processed and tempData._initialKeys is set, thus creating a cookie.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published