代码之家  ›  专栏  ›  技术社区  ›  Ralph Shillington

跨服务器场中的服务器使用视图状态

  •  1
  • Ralph Shillington  · 技术社区  · 15 年前

    对于ASP.NET 2.0,在同一服务器场中的服务器2是否可以使用在服务器1上生成的视图状态?

    5 回复  |  直到 15 年前
        1
  •  1
  •   Shea    15 年前

    只要防篡改保护/Mac关闭,我相信它可以。

        2
  •  2
  •   JP Alioto    15 年前

    是的,你可以。有几个选项可以确保可以在服务器场中的每台服务器上对视图状态进行解码。通常,在每台服务器上手动在每个machine.config中设置machinekey,使它们都相同。 But there are other options as well.

        3
  •  1
  •   Peter Mourfield    15 年前

    是的,web.config中的“machinekey”设置在每个服务器上都必须相同。

        4
  •  1
  •   baretta    15 年前

    在所有节点上使用相同的machinekey。将其放入machine.config或web.config中

        5
  •  0
  •   Christopher G. Lewis    15 年前

    阅读本文: How To: Configure MachineKey in ASP.NET 2.0

    基本上,您使用以下代码:

    using System;
    using System.Text;
    using System.Security;
    using System.Security.Cryptography;
    
    class App {
      static void Main(string[] argv) {
        int len = 128;
        if (argv.Length > 0)
          len = int.Parse(argv[0]);
        byte[] buff = new byte[len/2];
        RNGCryptoServiceProvider rng = new 
                                RNGCryptoServiceProvider();
        rng.GetBytes(buff);
        StringBuilder sb = new StringBuilder(len);
        for (int i=0; i<buff.Length; i++)
          sb.Append(string.Format("{0:X2}", buff[i]));
        Console.WriteLine(sb);
      }
    }
    

    以生成在您的农场中共享的机器密钥。