简体   繁体   English

这是索引财产吗?

[英]Is this an Indexed Property, yea or nea?

I'm trying to get the current machineKey that is being used to encrypt/decrypt my ViewState, etc. in an attempt to debug another issue. 我正在尝试获取用于加密/解密我的ViewState等的当前machineKey,以尝试调试另一个问题。 (My app is in a server farm and there are machine keys set in the machine.config and web.config of each server and application so in an attempt to debug an issue where some resources are not being decrypted properly. I'm experimenting with this to see which one is being used for encryption.) Here is my code snippet: (我的应用程序位于服务器场中,并且在每个服务器和应用程序的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()));

As is, line 3 is throwing an "Object reference not set to an instance of an object." 照原样,第3行抛出“对象引用未设置为对象实例”。 which means that I'm probably not setting that second null param correctly (property must be indexed, right?). 这意味着我可能没有正确设置第二个null参数(属性必须被索引,对吧?)。

But the ParameterInfo of the machineKey's ValidationKey property is returniung a length of zero (so the property is not indexed, right?). 但是machineKey的ValidationKey属性的ParameterInfo返回的长度为零(因此该属性未编制索引,对吗?)。

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

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

There is obviously something that I am overlooking here and would love a second pair of eyes to look at this. 很明显,我在这里可以忽略某些东西,并且希望再有一双眼睛可以看到这一点。 Any suggestions? 有什么建议么?

You are passing in the typeof(MachineKeySection), when you should be passing in an instance of MachineKeySection. 当您应该传递MachineKeySection的实例时,您传递的是typeof(MachineKeySection)。

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

Needs to be something like (taken from here ): 需要像这样(从此处获取 ):

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

So to answer your question, no it's not an indexed property. 因此,要回答您的问题,不,它不是索引属性。 You can check the documentation here . 您可以在此处查看文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM