简体   繁体   中英

using viewstate across servers in a farm

与Asp.net 2.0可以在同一服务器场中的Server2使用Server1上生成的viewstate吗?

Yes, you can. There are several options for making sure that your viewstate can be decoded on each server in the farm. Generally, you set the machineKey in each machine.config by hand on each server so they are all the same. But there are other options as well.

我相信只要关闭防篡改功能/ MAC,它就可以。

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

Use an identic machineKey on all nodes. Put it in machine.config, or web.config

Read this article: How To: Configure MachineKey in ASP.NET 2.0

Basically, you use this code:

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);
  }
}

to generate a machinekey that's shared across your farm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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