2010/06/21

.NET fix: System.Security.SecurityException: Requested registry access is not allowed.

If you get something like this:

Server Error in '/applicationname' Application.
---------------------------------------------------------------------------
Security Exception 
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Requested registry access is not allowed.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 
[SecurityException: Requested registry access is not allowed.]
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +473
....

I'm not sure there's a secured way, but adding permission for iis daemon user solve the problem for me.

1. Find out which deamon user your app is using, by looking up App_Pool and secruity section in event log.

2. Give the user permission to read/write access for the eventlog registry entry. To do so, open regedit and navigate to the key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
.
Right click and select Permissions, and add permission for the user.

3. restart iis and give it a try.

沒有留言:

Mercury簡易改裝

有同好有一樣的困擾 - 如何使用自己的data logging軟體,因此寫了這篇來分享我的簡易改裝。 Background 雲豆子 MERCURY roaster 烘豆機的設計是使用自行開發的軟體,來:1. 操控風門/火力; 2. data logging/自動烘焙。 ...