【发布时间】:2014-12-08 12:27:54
【问题描述】:
我有下面提到的代码:
string urlEncodedData = URL.Text;
byte[] encryptedData = HttpServerUtility.UrlTokenDecode(urlEncodedData);
Type machineKeySection = typeof(System.Web.Configuration.MachineKeySection);
Type[] paramTypes = new Type[] { typeof(bool), typeof(byte[]), typeof(byte[]), typeof(int), typeof(int) };
MethodInfo encryptOrDecryptData = machineKeySection.GetMethod("EncryptOrDecryptData", BindingFlags.Static | BindingFlags.NonPublic, null, paramTypes, null);
try
{
byte[] decryptedData = (byte[])encryptOrDecryptData.Invoke(null, new object[] { false, encryptedData, null, 0, encryptedData.Length });
string decrypted = Encoding.UTF8.GetString(decryptedData);
decryptedLabel.BackColor = Color.Lime;
decryptedLabel.Text = decrypted;
}
catch (TargetInvocationException)
{
decryptedLabel.BackColor = Color.Red;
decryptedLabel.Text = "Error decrypting data. Are you running your page on the same server and inside the same application as the web resource URL that was generated?";
}
它会解密并告诉我有关 webresource 的详细信息。 在本地它工作正常。
但在生产过程中,它总是给我来自 catch 块的以下消息
解密数据时出错。您是否在与生成的 Web 资源 URL 相同的服务器和相同的应用程序中运行您的页面?
我唯一的区别是使用 HTTPS 进行生产。上面的代码对 HTTPS 也有效吗,还是我必须对其进行更改?
【问题讨论】:
标签: c# asp.net .net https webresource.axd