如何设置的machineKey在Azure网站 [英] How to set machineKey on Azure Website

查看:147
本文介绍了如何设置的machineKey在Azure网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个Azure的网站。每当我部署,每个人都被注销,因为的machineKey 的变化。

I'm running an Azure Website. Whenever I deploy, everyone gets logged out because the machineKey changes.

我指定的的machineKey 的web.config 但这并没有解决问题。我相信这是因为Azure的自动覆盖的machineKey [1]

I specified the machineKey in the web.config but this didn't solve the issue. I believe this is because Azure automatically overwrites the machineKey [1].

我发现了几个类似的问题在这里,但答案链接到死链接。

I've found a couple of similar questions here but the answers link to dead links.

那么,有什么解决办法?肯定有,以保持用户登录,无论部署在Azure上的一种方式。

So, what's the solution? Surely there's a way to keep users logged in regardless of deployments on Azure.

推荐答案

试着复位经机键配置节的Application_Start

Try to reset the machine-key configuration section upon Application_Start:

protected void Application_Start()
{
    // ...

    var mksType = typeof(MachineKeySection);
    var mksSection = ConfigurationManager.GetSection("system.web/machineKey") as MachineKeySection;
    var resetMethod = mksType.GetMethod("Reset", BindingFlags.NonPublic | BindingFlags.Instance);

    var newConfig = new MachineKeySection();
    newConfig.ApplicationName = mksSection.ApplicationName;
    newConfig.CompatibilityMode = mksSection.CompatibilityMode;
    newConfig.DataProtectorType = mksSection.DataProtectorType;
    newConfig.Validation = mksSection.Validation;

    newConfig.ValidationKey = ConfigurationManager.AppSettings["MK_ValidationKey"];
    newConfig.DecryptionKey = ConfigurationManager.AppSettings["MK_DecryptionKey"];
    newConfig.Decryption = ConfigurationManager.AppSettings["MK_Decryption"]; // default: AES
    newConfig.ValidationAlgorithm = ConfigurationManager.AppSettings["MK_ValidationAlgorithm"]; // default: SHA1

    resetMethod.Invoke(mksSection, new object[] { newConfig });
}

以上假定您设置适当的值<&的appSettings GT; 部分:

<appSettings>
  <add key="MK_ValidationKey" value="...08EB13BEC0E42B3F0F06B2C319B..." />
  <add key="MK_DecryptionKey" value="...BB72FCE34A7B913DFC414E86BB5..." />
  <add key="MK_Decryption" value="AES" />
  <add key="MK_ValidationAlgorithm" value="SHA1" />
</appSettings>

但你可以从任何你喜欢的配置源加载您的实际值。

But you can load your actual values from any configuration source you like.

这篇关于如何设置的machineKey在Azure网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆