public async Task InvokeAsync(HttpContext httpContext) { var path = httpContext.Request.Path.ToString(); if (!path.StartsWith(Prefix, StringComparison.InvariantCultureIgnoreCase)) { await Next(httpContext); return; } path = path.Substring(Prefix.Length); var file = PublicAppEmbeddedResourceProvider.GetFile(path) ?? PublicComponentEmbeddedResourceProvider.GetFile(path); if (file == null) { await Next(httpContext); return; } if (path.EndsWith(".js")) { httpContext.Response.ContentType = "application/javascript"; } using (var read = EmbeddedResourceProvider.Open(file)) { await read.CopyToAsync(httpContext.Response.Body); } }
public void ProcessRequest(HttpContext context) { var path = context.Request.Path; if (!path.StartsWith(Prefix, StringComparison.InvariantCultureIgnoreCase)) { throw new Exception($"This handler should only be used within the Portal basepath ({Prefix})"); } path = path.Substring(Prefix.Length); var file = PublicAppEmbeddedResourceProvider.GetFile(path) ?? PublicComponentEmbeddedResourceProvider.GetFile(path); if (file == null) { throw new Exception($"This handler should only be used on an existing embedded resource"); } context.Response.ContentType = MimeMapping.GetMimeMapping(Path.GetExtension(path)); using (var read = EmbeddedResourceProvider.Open(file)) { read.CopyTo(context.Response.OutputStream); } }
void Context_BeginRequest(object sender, EventArgs e) { if (BasePathProvider == null) { BasePathProvider = DependencyResolver.Current.GetService <IBasePathProvider>(); Prefix = $"/{BasePathProvider.BasePath}/"; } if (PublicAppEmbeddedResourceProvider == null) { PublicAppEmbeddedResourceProvider = DependencyResolver.Current.GetService <IPublicAppEmbeddedResourceProvider>(); } if (PublicComponentEmbeddedResourceProvider == null) { PublicComponentEmbeddedResourceProvider = DependencyResolver.Current.GetService <IPublicComponentEmbeddedResourceProvider>(); } var context = ((HttpApplication)sender).Context; var path = context.Request.Path; if (!path.StartsWith(Prefix, StringComparison.InvariantCultureIgnoreCase)) { return; } path = path.Substring(Prefix.Length); var file = PublicAppEmbeddedResourceProvider.GetFile(path) ?? PublicComponentEmbeddedResourceProvider.GetFile(path); if (file == null) { return; } context.RemapHandler(new EmbeddedResourceHandler()); }