0

我正在尝试获取用于加密/解密我的 ViewState 等的当前 machineKey,以尝试调试另一个问题。(我的应用程序位于服务器场中,并且在每个服务器和应用程序的 machine.config 和 web.config 中设置了机器密钥,因此试图调试某些资源未正确解密的问题。我正在尝试看看哪个用于加密。)这是我的代码片段:

Line 1:  Type machineKeySection = typeof(MachineKeySection);
Line 2:  PropertyInfo machineKey = machineKeySection.GetProperty("ValidationKey");
Line 3:  Object validationKey = machineKey.GetValue(machineKeySection, null);
Line 4:  Response.Write(String.Format("Value: {1}", validationKey.ToString()));

照原样,第 3 行抛出“未设置对象实例的对象引用”。这意味着我可能没有正确设置第二个空参数(属性必须被索引,对吗?)。

但是 machineKey 的 ValidationKey 属性的 ParameterInfo 返回的长度为零(所以该属性没有被索引,对吧?)。

ParameterInfo[] paramInfo = machineKey.GetIndexParameters();
Response.Write(paramInfo.Length);

http://msdn.microsoft.com/en-us/library/b05d59ty(v=VS.90).aspx

很明显,我在这里忽略了一些东西,并且希望有第二双眼睛来看看这个。有什么建议么?

4

1 回答 1

0

当您应该传入 MachineKeySection 的实例时,您正在传入 typeof(MachineKeySection)。

Type machineKeySection = typeof(MachineKeySection);
Object validationKey = machineKey.GetValue(machineKeySection, null);

需要类似于(取自此处):

MachineKeySection machineKeySection = (MachineKeySection)config.GetSection("system.web/machineKey");
Object validationKey = machineKey.GetValue(machineKeySection, null);

因此,要回答您的问题,不,它不是索引属性。您可以在此处查看文档。

于 2011-06-23T00:33:53.150 回答