예제 #1
0
        public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) : base(callback, state)
        {
            if (context == null)
            {
                throw System.ServiceModel.Activation.FxTrace.Exception.ArgumentNull("context");
            }
            this.context     = context;
            this.flowContext = flowContext;
            if (ensureWFService)
            {
                if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.ensureWFService = false;
                }
                else
                {
                    this.ensureWFService = true;
                }
            }
            if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath))
            {
                if (!RouteTable.Routes.RouteExistingFiles && ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.AspNetRouteServiceVirtualPath = null;
                }
                else
                {
                    this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath;
                }
            }
            string strA = context.Request.HttpMethod ?? "";
            char   ch   = (strA.Length == 5) ? strA[0] : '\0';

            if (((ch == 'd') || (ch == 'D')) && (string.Compare(strA, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0))
            {
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    System.ServiceModel.Activation.Diagnostics.TraceUtility.TraceEvent(TraceEventType.Verbose, 0x90005, System.ServiceModel.Activation.SR.TraceCodeWebHostDebugRequest, this);
                }
                this.state = 1;
                base.Complete(true, null);
            }
            else
            {
                this.impersonationContext = new HostedImpersonationContext();
                if (flowContext && ServiceHostingEnvironment.AspNetCompatibilityEnabled)
                {
                    this.hostedThreadData = new System.ServiceModel.Activation.HostedThreadData();
                }
                Action <object> action = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ? WaitOnBeginRequestWithFlow : WaitOnBeginRequest;
                if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService)
                {
                    context.CompleteRequest();
                }
                context.Server.ScriptTimeout = 0x7fffffff;
                ServiceHostingEnvironment.IncrementRequestCount();
                IOThreadScheduler.ScheduleCallbackLowPriNoFlow(action, this);
            }
        }
 public void Close()
 {
     if (this.impersonationContext != null)
     {
         this.impersonationContext.Release();
         this.impersonationContext = null;
     }
 }
예제 #3
0
 public void Close()
 {
     if (impersonationContext != null)
     {
         impersonationContext.Release();
         impersonationContext = null;
     }
 }
 public void Close()
 {
     if (this.impersonationContext != null)
     {
         this.impersonationContext.Release();
         this.impersonationContext = null;
     }
 }
 internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
 {
     if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
     {
         if ((result.ImpersonationContext != null) && result.ImpersonationContext.IsImpersonated)
         {
             this.impersonationContext = result.ImpersonationContext;
             this.impersonationContext.AddRef();
         }
         this.currentThreadData = result.HostedThreadData;
     }
     this.OriginalRequestUri = result.OriginalRequestUri;
 }
 internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
 {
     if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
     {
         if ((result.ImpersonationContext != null) && result.ImpersonationContext.IsImpersonated)
         {
             this.impersonationContext = result.ImpersonationContext;
             this.impersonationContext.AddRef();
         }
         this.currentThreadData = result.HostedThreadData;
     }
     this.OriginalRequestUri = result.OriginalRequestUri;
 }
예제 #7
0
        internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
        {
            Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path");

            if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
            {
                if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated)
                {
                    this.impersonationContext = result.ImpersonationContext;
                    this.impersonationContext.AddRef();
                }

                currentThreadData = result.HostedThreadData;
            }

            this.OriginalRequestUri = result.OriginalRequestUri;
        }
        internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
        {
            Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path");

            if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
            {
                if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated)
                {
                    this.impersonationContext = result.ImpersonationContext;
                    this.impersonationContext.AddRef();
                }

                currentThreadData = result.HostedThreadData;
            }

            this.OriginalRequestUri = result.OriginalRequestUri;
        }
        public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) :
            base(callback, state)
        {
            if (context == null)
            {
                throw FxTrace.Exception.ArgumentNull("context");
            }

            AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

            HostedAspNetEnvironment.TrySetWebSocketVersion(context);
            this.context = context;
            // WebSockets require the integrated pipeline mode and the WebSocket IIS module to be loaded. If these conditions 
            // are not met, the HttpContext.IsWebSocketRequest property throws. Also, if these conditions are not met,
            // we do not let WebSocket listeners to be started (we fail the service activation), so setting the 'isWebSocketRequest' flag 
            // to false in this case will not create confusion (or make troubleshooting difficult).
            this.isWebSocketRequest = HttpRuntime.UsingIntegratedPipeline && AspNetEnvironment.Current.IsWebSocketModuleLoaded && this.context.Context.IsWebSocketRequest;
            this.flowContext = flowContext;
            if (ensureWFService)
            {
                // check for CBA scenario. if true, service should be handled by WCF instead of WF, 
                // set this.ensureWFservice to false
                if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.ensureWFService = false;
                }
                else
                {
                    this.ensureWFService = true;
                }
            }

            if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath))
            {
                // aspnet routing can hijack CBA request as we append {*pathInfo} to urlpattern and there is no real file for CBA 
                // check for CBA scenario. if the request is hijacked. i.e., 
                // 1) route maps to a virtual directory:
                // aspNetRouteServiceVirtualPath <> context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath 
                // if RouteExistingFiles <> true, set aspnetRouteServiceVirtualPath to null so that the request will be treated as CBA
                // if RouteExistingFiles == true, this hijack is by-design, do nothing
                // 2) route maps to a CBA entry:
                // aspNetRouteServiceVirtualPath == context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath
                // we will use RouteExistingFiles to decide which service should be activated. We do it in ServiceHostingEnviroment.HostingManager, 
                // as we cannot pass this info to the latter. 
                if (!RouteTable.Routes.RouteExistingFiles &&
                    ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.AspNetRouteServiceVirtualPath = null;
                }
                else
                {
                    this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath;
                }
            }

            // If this is a DEBUG request, complete right away and let ASP.NET handle it.
            string method = context.Request.HttpMethod ?? "";
            char firstMethodChar = method.Length == 5 ? method[0] : '\0';
            if ((firstMethodChar == 'd' || firstMethodChar == 'D') &&
                string.Compare(method, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.WebHostDebugRequest, SR.TraceCodeWebHostDebugRequest, this);
                }

                this.state = State.Completed;
                Complete(true, null);
                return;
            }

            this.impersonationContext = new HostedImpersonationContext();

            if (flowContext)
            {
                if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
                {
                    // Capture HttpContext/culture context if necessary.  Can be used later by HostedHttpInput to re-apply
                    // the culture during dispatch.  Also flowed here.
                    hostedThreadData = new HostedThreadData();
                }
            }

            // Set this up before calling IncrementRequestCount so if it fails, we don't leak a count.
            Action<object> iotsCallback = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ?
                WaitOnBeginRequestWithFlow : WaitOnBeginRequest;

            // Tell ASPNET to by-pass all the other events so no other http modules will
            // be invoked, Indigo basically takes over the request completely. This should
            // only be called in non-AspNetCompatibilityEnabled mode.
            if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService)
            {
                context.CompleteRequest();
            }

            // Prevent ASP.NET from generating thread aborts in relation to this request.
            context.Server.ScriptTimeout = int.MaxValue;

            ServiceHostingEnvironment.IncrementRequestCount(ref this.eventTraceActivity, context.Request.AppRelativeCurrentExecutionFilePath);

            IOThreadScheduler.ScheduleCallbackLowPriNoFlow(iotsCallback, this);
        }
 public void Close()
 {
     if (impersonationContext != null)
     {
         impersonationContext.Release();
         impersonationContext = null;
     }
 }
 public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) : base(callback, state)
 {
     if (context == null)
     {
         throw System.ServiceModel.Activation.FxTrace.Exception.ArgumentNull("context");
     }
     this.context = context;
     this.flowContext = flowContext;
     if (ensureWFService)
     {
         if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
         {
             this.ensureWFService = false;
         }
         else
         {
             this.ensureWFService = true;
         }
     }
     if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath))
     {
         if (!RouteTable.Routes.RouteExistingFiles && ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
         {
             this.AspNetRouteServiceVirtualPath = null;
         }
         else
         {
             this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath;
         }
     }
     string strA = context.Request.HttpMethod ?? "";
     char ch = (strA.Length == 5) ? strA[0] : '\0';
     if (((ch == 'd') || (ch == 'D')) && (string.Compare(strA, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0))
     {
         if (DiagnosticUtility.ShouldTraceVerbose)
         {
             System.ServiceModel.Activation.Diagnostics.TraceUtility.TraceEvent(TraceEventType.Verbose, 0x90005, System.ServiceModel.Activation.SR.TraceCodeWebHostDebugRequest, this);
         }
         this.state = 1;
         base.Complete(true, null);
     }
     else
     {
         this.impersonationContext = new HostedImpersonationContext();
         if (flowContext && ServiceHostingEnvironment.AspNetCompatibilityEnabled)
         {
             this.hostedThreadData = new System.ServiceModel.Activation.HostedThreadData();
         }
         Action<object> action = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ? WaitOnBeginRequestWithFlow : WaitOnBeginRequest;
         if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService)
         {
             context.CompleteRequest();
         }
         context.Server.ScriptTimeout = 0x7fffffff;
         ServiceHostingEnvironment.IncrementRequestCount();
         IOThreadScheduler.ScheduleCallbackLowPriNoFlow(action, this);
     }
 }
        public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) :
            base(callback, state)
        {
            if (context == null)
            {
                throw FxTrace.Exception.ArgumentNull("context");
            }

            AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

            HostedAspNetEnvironment.TrySetWebSocketVersion(context);
            this.context = context;
            // WebSockets require the integrated pipeline mode and the WebSocket IIS module to be loaded. If these conditions
            // are not met, the HttpContext.IsWebSocketRequest property throws. Also, if these conditions are not met,
            // we do not let WebSocket listeners to be started (we fail the service activation), so setting the 'isWebSocketRequest' flag
            // to false in this case will not create confusion (or make troubleshooting difficult).
            this.isWebSocketRequest = HttpRuntime.UsingIntegratedPipeline && AspNetEnvironment.Current.IsWebSocketModuleLoaded && this.context.Context.IsWebSocketRequest;
            this.flowContext        = flowContext;
            if (ensureWFService)
            {
                // check for CBA scenario. if true, service should be handled by WCF instead of WF,
                // set this.ensureWFservice to false
                if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.ensureWFService = false;
                }
                else
                {
                    this.ensureWFService = true;
                }
            }

            if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath))
            {
                // aspnet routing can hijack CBA request as we append {*pathInfo} to urlpattern and there is no real file for CBA
                // check for CBA scenario. if the request is hijacked. i.e.,
                // 1) route maps to a virtual directory:
                // aspNetRouteServiceVirtualPath <> context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath
                // if RouteExistingFiles <> true, set aspnetRouteServiceVirtualPath to null so that the request will be treated as CBA
                // if RouteExistingFiles == true, this hijack is by-design, do nothing
                // 2) route maps to a CBA entry:
                // aspNetRouteServiceVirtualPath == context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath
                // we will use RouteExistingFiles to decide which service should be activated. We do it in ServiceHostingEnviroment.HostingManager,
                // as we cannot pass this info to the latter.
                if (!RouteTable.Routes.RouteExistingFiles &&
                    ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.AspNetRouteServiceVirtualPath = null;
                }
                else
                {
                    this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath;
                }
            }

            // If this is a DEBUG request, complete right away and let ASP.NET handle it.
            string method          = context.Request.HttpMethod ?? "";
            char   firstMethodChar = method.Length == 5 ? method[0] : '\0';

            if ((firstMethodChar == 'd' || firstMethodChar == 'D') &&
                string.Compare(method, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.WebHostDebugRequest, SR.TraceCodeWebHostDebugRequest, this);
                }

                this.state = State.Completed;
                Complete(true, null);
                return;
            }

            this.impersonationContext = new HostedImpersonationContext();

            if (flowContext)
            {
                if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
                {
                    // Capture HttpContext/culture context if necessary.  Can be used later by HostedHttpInput to re-apply
                    // the culture during dispatch.  Also flowed here.
                    hostedThreadData = new HostedThreadData();
                }
            }

            // Set this up before calling IncrementRequestCount so if it fails, we don't leak a count.
            Action <object> iotsCallback = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ?
                                           WaitOnBeginRequestWithFlow : WaitOnBeginRequest;

            // Tell ASPNET to by-pass all the other events so no other http modules will
            // be invoked, Indigo basically takes over the request completely. This should
            // only be called in non-AspNetCompatibilityEnabled mode.
            if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService)
            {
                context.CompleteRequest();
            }

            // Prevent ASP.NET from generating thread aborts in relation to this request.
            context.Server.ScriptTimeout = int.MaxValue;

            ServiceHostingEnvironment.IncrementRequestCount(ref this.eventTraceActivity, context.Request.AppRelativeCurrentExecutionFilePath);

            IOThreadScheduler.ScheduleCallbackLowPriNoFlow(iotsCallback, this);
        }