public int ProcessRequest(IntPtr ecb, int iWRType)
        {
            IntPtr zero = IntPtr.Zero;

            if (iWRType == 2)
            {
                zero = ecb;
                ecb  = System.Web.UnsafeNativeMethods.GetEcb(zero);
            }
            ISAPIWorkerRequest wr = null;

            try
            {
                bool useOOP = iWRType == 1;
                wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP);
                wr.Initialize();
                string appPathTranslated        = wr.GetAppPathTranslated();
                string appDomainAppPathInternal = HttpRuntime.AppDomainAppPathInternal;
                if ((appDomainAppPathInternal == null) || StringUtil.EqualsIgnoreCase(appPathTranslated, appDomainAppPathInternal))
                {
                    HttpRuntime.ProcessRequestNoDemand(wr);
                    return(0);
                }
                HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged, System.Web.SR.GetString("Hosting_Phys_Path_Changed", new object[] { appDomainAppPathInternal, appPathTranslated }));
                return(1);
            }
            catch (Exception exception)
            {
                try
                {
                    WebBaseEvent.RaiseRuntimeError(exception, this);
                }
                catch
                {
                }
                if ((wr == null) || !(wr.Ecb == IntPtr.Zero))
                {
                    throw;
                }
                if (zero != IntPtr.Zero)
                {
                    System.Web.UnsafeNativeMethods.SetDoneWithSessionCalled(zero);
                }
                if (exception is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
                return(0);
            }
        }
Ejemplo n.º 2
0
        [SecurityPermission(SecurityAction.LinkDemand, Unrestricted = true)] // DevDiv #180492
        public int ProcessRequest(IntPtr ecb, int iWRType)
        {
            IntPtr pHttpCompletion = IntPtr.Zero;

            if (iWRType == WORKER_REQUEST_TYPE_IN_PROC_VERSION_2)
            {
                pHttpCompletion = ecb;
                ecb             = UnsafeNativeMethods.GetEcb(pHttpCompletion);
            }
            ISAPIWorkerRequest wr = null;

            try {
                bool useOOP = (iWRType == WORKER_REQUEST_TYPE_OOP);
                wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP);
                wr.Initialize();

                // check if app path matches (need to restart app domain?)
                String wrPath = wr.GetAppPathTranslated();
                String adPath = HttpRuntime.AppDomainAppPathInternal;

                if (adPath == null ||
                    StringUtil.EqualsIgnoreCase(wrPath, adPath))
                {
                    HttpRuntime.ProcessRequestNoDemand(wr);
                    return(0);
                }
                else
                {
                    // need to restart app domain
                    HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged,
                                                  SR.GetString(SR.Hosting_Phys_Path_Changed,
                                                               adPath,
                                                               wrPath));
                    return(1);
                }
            }
            catch (Exception e) {
                try {
                    WebBaseEvent.RaiseRuntimeError(e, this);
                } catch {}

                // Have we called HSE_REQ_DONE_WITH_SESSION?  If so, don't re-throw.
                if (wr != null && wr.Ecb == IntPtr.Zero)
                {
                    if (pHttpCompletion != IntPtr.Zero)
                    {
                        UnsafeNativeMethods.SetDoneWithSessionCalled(pHttpCompletion);
                    }
                    // if this is a thread abort exception, cancel the abort
                    if (e is ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                    // IMPORTANT: if this thread is being aborted because of an AppDomain.Unload,
                    // the CLR will still throw an AppDomainUnloadedException. The native caller
                    // must special case COR_E_APPDOMAINUNLOADED(0x80131014) and not
                    // call HSE_REQ_DONE_WITH_SESSION more than once.
                    return(0);
                }

                // re-throw if we have not called HSE_REQ_DONE_WITH_SESSION
                throw;
            }
        }