2011-06-23 48 views
0

我試圖獲取正在用於加密/解密我的ViewState等當前machineKey試圖調試另一個問題。 (我的應用程序位於服務器場中,並且在每臺服務器和應用程序的machine.config和web.config中都設置了機器密鑰,以嘗試調試某些資源未被正確解密的問題。此看到正被用於加密哪一個)這是我的代碼段:這是一個索引的屬性,是的還是nea?

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是,第3行是拋出「未設置爲一個對象的實例對象引用」。這意味着我可能沒有正確設置第二個空參數(屬性必須被索引,對嗎?)。

但machineKey的ValidationKey屬性的ParameterInfo是returniung長度爲零(所以屬性沒有索引,對不對?)。

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

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

顯然有我在這裏忽視的東西,他會喜歡第二一雙眼睛看這個。有什麼建議麼?

回答

0

當傳遞MachineKeySection的實例時,您正在傳入typeof(MachineKeySection)。

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

需要是類似(從here拍攝):

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

因此,要回答你的問題,沒有它不是一個索引屬性。您可以檢查文檔here

相關問題