Beispiel #1
0
        private void MakeRequest(System.Web.UnsafeNativeMethods.StateProtocolVerb verb, string id, System.Web.UnsafeNativeMethods.StateProtocolExclusive exclusiveAccess, int extraFlags, int timeout, int lockCookie, byte[] buf, int cb, int networkTimeout, out System.Web.UnsafeNativeMethods.SessionNDMakeRequestResults results)
        {
            int num;
            OutOfProcConnection o = null;
            bool checkVersion     = false;

            SessionIDManager.CheckIdLength(id, true);
            if (this._partitionInfo == null)
            {
                this._partitionInfo = (StateServerPartitionInfo)s_partitionManager.GetPartition(this._partitionResolver, id);
                if (this._partitionInfo == null)
                {
                    throw new HttpException(System.Web.SR.GetString("Bad_partition_resolver_connection_string", new object[] { "PartitionManager" }));
                }
            }
            try
            {
                HandleRef ref2;
                o = (OutOfProcConnection)this._partitionInfo.RetrieveResource();
                if (o != null)
                {
                    ref2 = new HandleRef(this, o._socketHandle.Handle);
                }
                else
                {
                    ref2 = new HandleRef(this, INVALID_SOCKET);
                }
                if (this._partitionInfo.StateServerVersion == -1)
                {
                    checkVersion = true;
                }
                string uri = HttpUtility.UrlEncode(s_uribase + id);
                num = System.Web.UnsafeNativeMethods.SessionNDMakeRequest(ref2, this._partitionInfo.Server, this._partitionInfo.Port, networkTimeout, verb, uri, exclusiveAccess, extraFlags, timeout, lockCookie, buf, cb, checkVersion, out results);
                if (o != null)
                {
                    if (results.socket == INVALID_SOCKET)
                    {
                        o.Detach();
                        o = null;
                    }
                    else if (results.socket != ref2.Handle)
                    {
                        o._socketHandle = new HandleRef(this, results.socket);
                    }
                }
                else if (results.socket != INVALID_SOCKET)
                {
                    o = new OutOfProcConnection(results.socket);
                }
                if (o != null)
                {
                    this._partitionInfo.StoreResource(o);
                }
            }
            catch
            {
                if (o != null)
                {
                    o.Dispose();
                }
                throw;
            }
            if (num == 0)
            {
                if (results.httpStatus == 400)
                {
                    if (s_usePartition)
                    {
                        throw new HttpException(System.Web.SR.GetString("Bad_state_server_request_partition_resolver", new object[] { s_configPartitionResolverType, this._partitionInfo.Server, this._partitionInfo.Port.ToString(CultureInfo.InvariantCulture) }));
                    }
                    throw new HttpException(System.Web.SR.GetString("Bad_state_server_request"));
                }
                if (checkVersion)
                {
                    this._partitionInfo.StateServerVersion = results.stateServerMajVer;
                    if (this._partitionInfo.StateServerVersion < WHIDBEY_MAJOR_VERSION)
                    {
                        if (s_usePartition)
                        {
                            throw new HttpException(System.Web.SR.GetString("Need_v2_State_Server_partition_resolver", new object[] { s_configPartitionResolverType, this._partitionInfo.Server, this._partitionInfo.Port.ToString(CultureInfo.InvariantCulture) }));
                        }
                        throw new HttpException(System.Web.SR.GetString("Need_v2_State_Server"));
                    }
                }
            }
            else
            {
                HttpException exception = CreateConnectionException(this._partitionInfo.Server, this._partitionInfo.Port, num);
                string        str2      = null;
                switch (results.lastPhase)
                {
                case 0:
                    str2 = System.Web.SR.GetString("State_Server_detailed_error_phase0");
                    break;

                case 1:
                    str2 = System.Web.SR.GetString("State_Server_detailed_error_phase1");
                    break;

                case 2:
                    str2 = System.Web.SR.GetString("State_Server_detailed_error_phase2");
                    break;

                case 3:
                    str2 = System.Web.SR.GetString("State_Server_detailed_error_phase3");
                    break;
                }
                WebBaseEvent.RaiseSystemEvent(System.Web.SR.GetString("State_Server_detailed_error", new object[] { str2, "0x" + num.ToString("X08", CultureInfo.InvariantCulture), cb.ToString(CultureInfo.InvariantCulture) }), this, 0xbc1, 0xc360, exception);
                throw exception;
            }
        }
Beispiel #2
0
        internal unsafe SessionStateStoreData DoGet(HttpContext context, string id, System.Web.UnsafeNativeMethods.StateProtocolExclusive exclusiveAccess, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actionFlags)
        {
            SessionStateStoreData data   = null;
            UnmanagedMemoryStream stream = null;

            System.Web.UnsafeNativeMethods.SessionNDMakeRequestResults results;
            locked          = false;
            lockId          = null;
            lockAge         = TimeSpan.Zero;
            actionFlags     = SessionStateActions.None;
            results.content = IntPtr.Zero;
            try
            {
                this.MakeRequest(System.Web.UnsafeNativeMethods.StateProtocolVerb.GET, id, exclusiveAccess, 0, 0, 0, null, 0, s_networkTimeout, out results);
                int httpStatus = results.httpStatus;
                if (httpStatus != 200)
                {
                    if (httpStatus != 0x1a7)
                    {
                        return(data);
                    }
                }
                else
                {
                    int contentLength = results.contentLength;
                    if (contentLength > 0)
                    {
                        try
                        {
                            stream = new UnmanagedMemoryStream((byte *)results.content, (long)contentLength);
                            data   = SessionStateUtility.DeserializeStoreData(context, stream, s_configCompressionEnabled);
                        }
                        finally
                        {
                            if (stream != null)
                            {
                                stream.Close();
                            }
                        }
                        lockId      = results.lockCookie;
                        actionFlags = (SessionStateActions)results.actionFlags;
                    }
                    return(data);
                }
                if (0 <= results.lockAge)
                {
                    if (results.lockAge < 0x1e13380)
                    {
                        lockAge = new TimeSpan(0, 0, results.lockAge);
                    }
                    else
                    {
                        lockAge = TimeSpan.Zero;
                    }
                }
                else
                {
                    DateTime now = DateTime.Now;
                    if ((0L < results.lockDate) && (results.lockDate < now.Ticks))
                    {
                        lockAge = (TimeSpan)(now - new DateTime(results.lockDate));
                    }
                    else
                    {
                        lockAge = TimeSpan.Zero;
                    }
                }
                locked = true;
                lockId = results.lockCookie;
            }
            finally
            {
                if (results.content != IntPtr.Zero)
                {
                    System.Web.UnsafeNativeMethods.SessionNDFreeBody(new HandleRef(this, results.content));
                }
            }
            return(data);
        }