3

We have recently migrate our site to .NET 4.5, one of the change was adding targetFramework="4.5" to httpRuntime to opt in for ASP.NET 4.5 behaviours. Everything was working as expected until we try to reproduce some exception locally. Prior to the upgrade, we were able to use view state decoder such as http://www.binaryfortress.com/ASPNET-ViewState-Helper/ to see the values stored in the viewstate. However, this doesn't seem to be possible anymore, the viewstate seems to be encrypted with a random key on every page request (changes every time).

So, does anyone know the steps to properly decrypt/decode viewstate in ASP.NET 4.5?

BlueFox
  • 950
  • 13
  • 29

2 Answers2

7

The encryption approach in .NET 4.5 has changed dramatically since ASP.NET 4. This blog entry as a good overview: Cryptographic Improvements in ASP.NET 4.5, pt. 2.

When you updated your Web.config file to have the following markup:

<httpRuntime targetFramework="4.5" />

That turned on ASP.NET 4.5's new cryptography features. You can explicitly turn off this ASP.NET 4.5-specific view state encoding logic by adding the machineKey element to your configuration:

<machineKey compatibilityMode="Framework20SP1" />

Hope this helps.

Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
Scott Mitchell
  • 8,659
  • 3
  • 55
  • 71
  • Thanks for the explanations, I was hoping that there's some way to decode the 4.5 encrypted viewstate as we are unable to reproduce the exception. – BlueFox Jan 08 '13 at 15:14
  • Thanks for this anyway - that tag does indeed allow ASP.NET ViewState Helper to work with .NET v4.5.x website. Handy for debugging and generally finding out what's in viewstate – Rob Nicholson Apr 25 '15 at 13:25
-1

You could set ViewStateEncryptionMode to "Never" in the appropriate <%@ Page %> directive.

White hawk
  • 1,468
  • 1
  • 15
  • 23