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); } }
private bool CheckServiceExists(string serviceFile) { try { return(ServiceHostingEnvironment.IsConfigurationBasedService(serviceFile) || HostingEnvironmentWrapper.ServiceFileExists(serviceFile)); } catch (ArgumentException exception) { MsmqDiagnostics.ExpectedException(exception); return(false); } }
bool CheckServiceExists(string serviceFile) { try { return((ServiceHostingEnvironment.IsConfigurationBasedService(serviceFile) || HostingEnvironmentWrapper.ServiceFileExists(serviceFile)) && AspNetEnvironment.Current.IsWithinApp(VirtualPathUtility.ToAbsolute(serviceFile))); } catch (ArgumentException ex) { MsmqDiagnostics.ExpectedException(ex); return(false); } }
static public IAsyncResult BeginProcessRequest(object sender, EventArgs e, AsyncCallback cb, object extraData) { if (ServiceHttpModule.disabled) { return(GetCompletedAsyncResult(cb, extraData)); } try { ServiceHostingEnvironment.SafeEnsureInitialized(); } catch (SecurityException exception) { ServiceHttpModule.disabled = true; DiagnosticUtility.TraceHandledException(exception, TraceEventType.Warning); // If requesting a .svc file, the HttpHandler will try to handle it. It will call // SafeEnsureInitialized() again, which will fail with the same exception (it is // idempotent on failure). This is the correct behavior. return(GetCompletedAsyncResult(cb, extraData)); } HttpApplication application = (HttpApplication)sender; // Check to see whether the extension is supported. string extension = application.Request.CurrentExecutionFilePathExtension; if (string.IsNullOrEmpty(extension)) { return(GetCompletedAsyncResult(cb, extraData)); } ServiceHostingEnvironment.ServiceType serviceType = ServiceHostingEnvironment.GetServiceType(extension); // do extension check first so that we do not need to do it in aspnetrouting/configurationbasedactivation if (serviceType == ServiceHostingEnvironment.ServiceType.Unknown) { return(GetCompletedAsyncResult(cb, extraData)); } // check for AspNetcompat if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { // remap httphandler for xamlx in CBA, since there is No physical file and // the xamlx httphandlerfactory will do file exist checking if (serviceType == ServiceHostingEnvironment.ServiceType.Workflow && ServiceHostingEnvironment.IsConfigurationBasedService(application)) { IHttpHandler cbaHandler = new ServiceHttpHandlerFactory().GetHandler( application.Context, application.Request.RequestType, application.Request.RawUrl.ToString(), application.Request.PhysicalApplicationPath); application.Context.RemapHandler(cbaHandler); } return(GetCompletedAsyncResult(cb, extraData)); } if (serviceType == ServiceHostingEnvironment.ServiceType.WCF) { return(new HostedHttpRequestAsyncResult(application, false, false, cb, extraData)); } if (serviceType == ServiceHostingEnvironment.ServiceType.Workflow) { return(new HostedHttpRequestAsyncResult(application, false, true, cb, extraData)); } return(GetCompletedAsyncResult(cb, extraData)); }
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); }
private static void ProcessRequest(object sender, EventArgs e) { if (!disabled) { try { ServiceHostingEnvironment.SafeEnsureInitialized(); } catch (SecurityException exception) { disabled = true; if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning); } return; } HttpApplication application = (HttpApplication)sender; string currentExecutionFilePathExtension = application.Request.CurrentExecutionFilePathExtension; if (!string.IsNullOrEmpty(currentExecutionFilePathExtension)) { ServiceHostingEnvironment.ServiceType serviceType = ServiceHostingEnvironment.GetServiceType(currentExecutionFilePathExtension); if (serviceType != ServiceHostingEnvironment.ServiceType.Unknown) { if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { if ((serviceType == ServiceHostingEnvironment.ServiceType.Workflow) && ServiceHostingEnvironment.IsConfigurationBasedService(application)) { application.Context.RemapHandler(new HttpHandler()); } } else { switch (serviceType) { case ServiceHostingEnvironment.ServiceType.WCF: HostedHttpRequestAsyncResult.ExecuteSynchronous(application, false, false); return; case ServiceHostingEnvironment.ServiceType.Workflow: HostedHttpRequestAsyncResult.ExecuteSynchronous(application, false, true); break; } } } } } }
public static IAsyncResult BeginProcessRequest(object sender, EventArgs e, AsyncCallback cb, object extraData) { if (!disabled) { try { ServiceHostingEnvironment.SafeEnsureInitialized(); } catch (SecurityException exception) { disabled = true; if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning); } return(cachedAsyncResult); } HttpApplication application = (HttpApplication)sender; string currentExecutionFilePathExtension = application.Request.CurrentExecutionFilePathExtension; if (string.IsNullOrEmpty(currentExecutionFilePathExtension)) { return(cachedAsyncResult); } ServiceHostingEnvironment.ServiceType serviceType = ServiceHostingEnvironment.GetServiceType(currentExecutionFilePathExtension); if (serviceType == ServiceHostingEnvironment.ServiceType.Unknown) { return(cachedAsyncResult); } if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { if ((serviceType == ServiceHostingEnvironment.ServiceType.Workflow) && ServiceHostingEnvironment.IsConfigurationBasedService(application)) { IHttpHandler handler = new ServiceHttpHandlerFactory().GetHandler(application.Context, application.Request.RequestType, application.Request.RawUrl.ToString(), application.Request.PhysicalApplicationPath); application.Context.RemapHandler(handler); } return(cachedAsyncResult); } switch (serviceType) { case ServiceHostingEnvironment.ServiceType.WCF: return(new HostedHttpRequestAsyncResult(application, false, false, cb, extraData)); case ServiceHostingEnvironment.ServiceType.Workflow: return(new HostedHttpRequestAsyncResult(application, false, true, cb, extraData)); } } return(cachedAsyncResult); }