internal override bool IsWithinApp(string absoluteVirtualPath) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); string matchedAppPath = this.FindLongestMatchingAppPath(absoluteVirtualPath); string curAppPath = VirtualPathUtility.AppendTrailingSlash(HostingEnvironmentWrapper.ApplicationVirtualPath); return(string.Compare(matchedAppPath, curAppPath, StringComparison.OrdinalIgnoreCase) == 0); }
public override Uri[] GetBaseAddresses(string virtualPath) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); Uri[] addresses = new Uri[listenAddresses.Count]; for (int i = 0; i < listenAddresses.Count; i++) { string absoluteVirtualPath = VirtualPathUtility.ToAbsolute(virtualPath, HostingEnvironmentWrapper.ApplicationVirtualPath); addresses[i] = new Uri(listenAddresses[i].BaseAddress, absoluteVirtualPath); } return(addresses); }
internal static object UnsafeGetSectionFromWebConfigurationManager(string sectionPath, string virtualPath) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); if (virtualPath != null) { return(WebConfigurationManager.GetSection(sectionPath, virtualPath)); } else { return(WebConfigurationManager.GetSection(sectionPath)); } }
private static void OnBeginRequestWithFlow(object state) { HostedHttpRequestAsyncResult result = (HostedHttpRequestAsyncResult)state; using (IDisposable disposable = null) { if (result.flowContext && (result.hostedThreadData != null)) { disposable = result.hostedThreadData.CreateContext(); } AspNetPartialTrustHelpers.PartialTrustInvoke(ContextOnBeginRequest, result); } }
public override bool IsWebConfigAboveApplication(object configHostingContext) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); WebContext context = configHostingContext as WebContext; if (context != null) { return(context.ApplicationLevel == WebApplicationLevel.AboveApplication); } return(false); // if we don't recognize the context we can't enforce the special web.config logic }
public MsmqHostedTransportManager(string[] hosts, MsmqUri.IAddressTranslator addressing) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.hosts = hosts; this.bindingMonitors = new List <MsmqBindingMonitor>(); this.addressing = addressing; this.filter = new HostedBindingFilter(HostingEnvironment.ApplicationVirtualPath, addressing); foreach (string host in this.hosts) { MsmqBindingMonitor monitor = new MsmqBindingMonitor(host, TimeSpan.FromMinutes(5), true); monitor.AddFilter(this.filter); monitor.Open(); this.bindingMonitors.Add(monitor); } }
bool GetServiceFileStreamOrCompiledCustomString(string virtualPath, Uri[] baseAddresses, out Stream serviceFileStream, out string compiledCustomString) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); IDisposable unsafeImpersonate = null; compiledCustomString = null; serviceFileStream = null; try { try { try { } finally { unsafeImpersonate = HostingEnvironmentWrapper.UnsafeImpersonate(); } if (HostingEnvironment.VirtualPathProvider.FileExists(virtualPath)) { serviceFileStream = HostingEnvironment.VirtualPathProvider.GetFile(virtualPath).Open(); return(true); } else { if (!AspNetEnvironment.Current.IsConfigurationBased) { compiledCustomString = BuildManager.GetCompiledCustomString(baseAddresses[0].AbsolutePath); } return(false); } } finally { if (null != unsafeImpersonate) { unsafeImpersonate.Dispose(); } } } catch { throw; } }
void AddSupportedVersions(WorkflowServiceHost workflowServiceHost, WorkflowService baseService) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); IList <Tuple <string, Stream> > streams = null; string xamlFileName = Path.GetFileNameWithoutExtension(VirtualPathUtility.GetFileName(this.xamlVirtualFile)); GetSupportedVersionStreams(xamlFileName, out streams); if (streams != null) { try { foreach (Tuple <string, Stream> stream in streams) { try { WorkflowService service = CreatetWorkflowServiceAndSetCompiledExpressionRoot(stream.Item1, stream.Item2, baseService.Name); if (service != null) { workflowServiceHost.SupportedVersions.Add(service); } } catch (Exception e) { Exception newException; if (Fx.IsFatal(e) || !TryWrapSupportedVersionException(stream.Item1, e, out newException)) { throw; } throw FxTrace.Exception.AsError(newException); } } } finally { foreach (Tuple <string, Stream> stream in streams) { stream.Item2.Dispose(); } } } }
public override bool IsWindowsAuthenticationConfigured() { if (!this.isWindowsAuthentication.HasValue) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); AuthenticationSection authSection = (AuthenticationSection)UnsafeGetConfigurationSection("system.web/authentication"); if (authSection != null) { this.isWindowsAuthentication = (authSection.Mode == AuthenticationMode.Windows); } else { this.isWindowsAuthentication = false; } } return(this.isWindowsAuthentication.Value); }
public override AuthenticationSchemes GetAuthenticationSchemes(Uri baseAddress) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); string fileName = VirtualPathUtility.GetFileName(baseAddress.AbsolutePath); string virtualPath = ServiceHostingEnvironment.CurrentVirtualPath; string completePath; if (virtualPath != null && virtualPath.EndsWith("/", StringComparison.Ordinal)) { completePath = virtualPath + fileName; } else { completePath = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", virtualPath, fileName); } AuthenticationSchemes supportedSchemes = HostedTransportConfigurationManager.MetabaseSettings.GetAuthenticationSchemes(completePath); return(supportedSchemes); }
protected MsmqHostedTransportConfiguration(MsmqUri.IAddressTranslator addressing) : base(addressing.Scheme) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); string[] bindings = HostedTransportConfigurationManager.MetabaseSettings.GetBindings(addressing.Scheme); this.uniqueManager = new MsmqHostedTransportManager(bindings, addressing); for (int i = 0; i < bindings.Length; i++) { Uri address = addressing.CreateUri(bindings[i], HostingEnvironment.ApplicationVirtualPath, false); this.ListenAddresses.Add(new BaseUriWithWildcard(address, TransportDefaults.HostNameComparisonMode)); UniqueTransportManagerRegistration registration = new UniqueTransportManagerRegistration(uniqueManager, address, TransportDefaults.HostNameComparisonMode); Msmq.StaticTransportManagerTable.RegisterUri(address, TransportDefaults.HostNameComparisonMode, registration); } this.uniqueManager.Start(null); }
public HostedRequestHttpOutput(HostedHttpRequestAsyncResult result, IHttpTransportFactorySettings settings, Message message, HostedHttpContext context) : base(settings, message, false, false) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.result = result; this.context = context; if (TransferModeHelper.IsResponseStreamed(settings.TransferMode)) { result.SetTransferModeToStreaming(); } if (message.IsFault) { this.statusCode = (int)HttpStatusCode.InternalServerError; } else { this.statusCode = (int)HttpStatusCode.OK; } }
HostedServiceTransportSettings GetTransportSettings(string virtualPath) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); //Make sure we get relative virtual path. string relativeVirtualPath = VirtualPathUtility.ToAppRelative(virtualPath, HostingEnvironmentWrapper.ApplicationVirtualPath); HostedServiceTransportSettings transportSettings; if (!transportSettingsTable.TryGetValue(relativeVirtualPath, out transportSettings)) { lock (ThisLock) { if (!transportSettingsTable.TryGetValue(relativeVirtualPath, out transportSettings)) { transportSettings = CreateTransportSettings(relativeVirtualPath); transportSettingsTable.Add(relativeVirtualPath, transportSettings); } } } return(transportSettings); }
public void TraceConnectionInformation(HostedHttpRequestAsyncResult result) { if (result != null && DiagnosticUtility.ShouldTraceInformation && canTraceConnectionInformation) { try { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); IServiceProvider provider = (IServiceProvider)result.Application.Context; HttpWorkerRequest workerRequest = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest)); string localAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", workerRequest.GetLocalAddress(), workerRequest.GetLocalPort()); string remoteAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", workerRequest.GetRemoteAddress(), workerRequest.GetRemotePort()); TraceUtility.TraceHttpConnectionInformation(localAddress, remoteAddress, this); } catch (SecurityException e) { canTraceConnectionInformation = false; // not re-throwing on purpose DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); } } }
public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer) : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer)) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.result = hostedContext.result; }
internal static void GetSupportedVersionStreams(string xamlFileName, out IList <Tuple <string, Stream> > streams) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); string virtualFileFolder = string.Format(CultureInfo.InvariantCulture, "~\\{0}", Path.Combine(SupportedVersionsFolder, xamlFileName)); IDisposable unsafeImpersonate = null; List <Tuple <string, Stream> > streamList = new List <Tuple <string, Stream> >(); bool cleanExit = false; streams = null; try { try { try { } finally { unsafeImpersonate = HostingEnvironmentWrapper.UnsafeImpersonate(); } if (HostingEnvironment.VirtualPathProvider.DirectoryExists(virtualFileFolder)) { string xamlFileFolder = HostingEnvironmentWrapper.MapPath(virtualFileFolder); string[] files = Directory.GetFiles(xamlFileFolder, "*.xamlx"); foreach (string file in files) { Stream activityStream; string path = Path.Combine(SupportedVersionsFolder, xamlFileName, Path.GetFileName(file)); string virtualFile = string.Format(CultureInfo.InvariantCulture, "~\\{0}", path); if (HostingEnvironment.VirtualPathProvider.FileExists(virtualFile)) { activityStream = HostingEnvironment.VirtualPathProvider.GetFile(virtualFile).Open(); streamList.Add(Tuple.Create(path, activityStream)); } } } cleanExit = true; } finally { if (unsafeImpersonate != null) { unsafeImpersonate.Dispose(); unsafeImpersonate = null; } } } catch { cleanExit = false; throw; } finally { if (cleanExit) { streams = streamList; } else { foreach (Tuple <string, Stream> stream in streamList) { stream.Item2.Dispose(); } } } }
internal XamlBuildProviderExtension() { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); }
public HostedBindingFilter(string path, MsmqUri.IAddressTranslator addressing) : base(path, addressing) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); }
static Guid GetRequestTraceIdentifier(IServiceProvider provider) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); return(((HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest))).RequestTraceIdentifier); }
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 HostedInputStream(HostedHttpContext hostedContext) : base(hostedContext.result.GetInputStream()) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.result = hostedContext.result; }
public override void EnsureAllReferencedAssemblyLoaded() { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); BuildManager.GetReferencedAssemblies(); }