Amazon EC2 multiple servers share session state

ぃ、小莉子 提交于 2019-12-08 05:13:53

问题


I have a bunch of EC2 servers that are load balanced. Some of the servers are not sharing session, and users keep getting logged in and out.

How can I make all the server share the one session, possibly even using a partitionresolver solution

    public class PartitionResolver : System.Web.IPartitionResolver
    {
        private String[] partitions;

        public void Initialize()
        {
            // create the partition connection string table
            //                           web1,            web2
            partitions = new String[] { "192.168.1.1" };
        }

        public String ResolvePartition(Object key)
        {
            String oHost = System.Web.HttpContext.Current.Request.Url.Host.ToLower().Trim();

            if (oHost.StartsWith("10.0.0") || oHost.Equals("localhost"))
                return "tcpip=127.0.0.1:42424";

            String sid = (String)key;

            // hash the incoming session ID into
            // one of the available partitions
            Int32 partitionID = Math.Abs(sid.GetHashCode()) % partitions.Length;

            return ("tcpip=" + partitions[partitionID] + ":42424");
        }
    }

-theo


回答1:


http://www.c-sharpcorner.com/UploadFile/gopenath/Page107182007032219AM/Page1.aspx



来源:https://stackoverflow.com/questions/2431319/amazon-ec2-multiple-servers-share-session-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!