Get Windows Service and ASP website on Windows 2008 to read same Registry Keys?
-
07-03-2021 - |
문제
I have a shared class which calls the following registry key which is used by a Windows Service and also an ASP MVC3 website:
irsalKey = Registry.LocalMachine
.CreateSubKey("SOFTWARE")
.CreateSubKey("MyApp");
On my local (Win7 32bit) PC this works as expected.
On my test 2008 server, the Service read/writes the "Wow6432" node, but website does not? My guess is that the service is 32bit (uses 32 bit binaries) but the website is 64bit under IIS?
What can I do so that both read/write the same keys? It doesn't matter WHICH key this is, but it needs to be the same for both!
Thx
해결책 2
Googling pointed me to use the following:
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
It IS in MSDN, but the documentation wasn't too clear (to me anyway!) but this forces any RegistryKey to use it's 32bit version.
다른 팁
You could try explicitly compiling the website for x86 instead of AnyCPU - that might force it to 32 bit mode. (set up a new platform in the Build/Configuration Manager menu)
You'd also have to turn on the app pool option in IIS to enable 32 bit applications (advanced settings on the app pool).