Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Machine Key changes when app pool is recycled

Tags:

I am using MachineKey API to encrypt/decrypt a piece of information in an ASP.NET application. I am using

MachineKey.Encode(data, MachineKeyProtection.All)

and

MachineKey.Decode(data, MachineKeyProtection.All)

methods of API. Everything works great on Windows 8 and Windows Server 2012 when Load User Profile is enabled. The problem is for some reason it doesn't survive app pool restart on Windows Server 2008 R2 with IIS 7.5.

Initially I had impression that I will need to enable Load User Profile setting on Application Pool but that doesn't make any difference. Any idea what I could be missing here?

Thanks

like image 620
Mazhar Qayyum Avatar asked Nov 13 '15 13:11

Mazhar Qayyum


People also ask

What happens when application pool is recycled?

Recycling means that the worker process that handles requests for that application pool is terminated and a new one is started. This is generally done to avoid unstable states that can lead to application crashes, hangs, or memory leaks.

Does recycling app pool clear session?

As an aside you should schedule any application pool recycles to occur during off-peak hours, as you've realised it will clear any active sessions and will break the user experience if the application relies on session storage.

What causes an application pool in IIS to recycle?

Cause: Application pools are configured to recycle when memory limits are exceeded. Resolution: Change the application pool recycling settings in Internet Information Services (IIS).


1 Answers

It could be that a new machine key is being generated by IIS each time the Application Pool recycles. Try setting a static machine key in your web.config as described here: IIS 7 Tip #10 You can generate machine keys from the IIS manager. Without explicitly setting a static machine key, your encryption/decryption key is a moving target.

like image 69
pstricker Avatar answered Sep 28 '22 00:09

pstricker